Browse Source

Merge pull request #1531 from jasonlewis/eloquent/bug/find

Allow find to be called anywhere on an Eloquent Model
Taylor Otwell 12 years ago
parent
commit
eb5d68f201
2 changed files with 17 additions and 13 deletions
  1. 1 13
      laravel/database/eloquent/model.php
  2. 16 0
      laravel/database/eloquent/query.php

+ 1 - 13
laravel/database/eloquent/model.php

@@ -225,18 +225,6 @@ abstract class Model {
 		return $model->query()->where($model->key(), '=', $id)->update($model->attributes);
 		return $model->query()->where($model->key(), '=', $id)->update($model->attributes);
 	}
 	}
 
 
-	/**
-	 * Find a model by its primary key.
-	 *
-	 * @param  string  $id
-	 * @param  array   $columns
-	 * @return Model
-	 */
-	public function _find($id, $columns = array('*'))
-	{
-		return $this->query()->where(static::$key, '=', $id)->first($columns);
-	}
-
 	/**
 	/**
 	 * Get all of the models in the database.
 	 * Get all of the models in the database.
 	 *
 	 *
@@ -762,7 +750,7 @@ abstract class Model {
 			return static::$$method;
 			return static::$$method;
 		}
 		}
 
 
-		$underscored = array('with', 'find', 'query');
+		$underscored = array('with', 'query');
 
 
 		// Some methods need to be accessed both staticly and non-staticly so we'll
 		// Some methods need to be accessed both staticly and non-staticly so we'll
 		// keep underscored methods of those methods and intercept calls to them
 		// keep underscored methods of those methods and intercept calls to them

+ 16 - 0
laravel/database/eloquent/query.php

@@ -50,6 +50,22 @@ class Query {
 		$this->table = $this->table();
 		$this->table = $this->table();
 	}
 	}
 
 
+	/**
+	 * Find a model by its primary key.
+	 * 
+	 * @param  mixed  $id
+	 * @param  array  $columns
+	 * @return mixed
+	 */
+	public function find($id, $columns = array('*'))
+	{
+		$model = $this->model;
+
+		$this->table->where($model::$key, '=', $id);
+
+		return $this->first($columns);
+	}
+
 	/**
 	/**
 	 * Get the first model result for the query.
 	 * Get the first model result for the query.
 	 *
 	 *