Commit eb5d68f2 by Taylor Otwell

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

Allow find to be called anywhere on an Eloquent Model
parents 082fc0b3 a422e069
...@@ -226,18 +226,6 @@ abstract class Model { ...@@ -226,18 +226,6 @@ abstract class Model {
} }
/** /**
* 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.
* *
* @return array * @return array
...@@ -762,7 +750,7 @@ abstract class Model { ...@@ -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
......
...@@ -51,6 +51,22 @@ class Query { ...@@ -51,6 +51,22 @@ class Query {
} }
/** /**
* 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.
* *
* @param array $columns * @param array $columns
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment