From a68d2242d3a60e2d3fdd0a40aba0fbeaed2aa40b Mon Sep 17 00:00:00 2001 From: Jason Lewis Date: Tue, 18 Dec 2012 19:14:51 +1100 Subject: [PATCH 1/2] Add the find method to the Eloquent Query class. Signed-off-by: Jason Lewis --- laravel/database/eloquent/query.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/laravel/database/eloquent/query.php b/laravel/database/eloquent/query.php index 3aee79c9..2d162e8e 100644 --- a/laravel/database/eloquent/query.php +++ b/laravel/database/eloquent/query.php @@ -50,6 +50,22 @@ public function __construct($model) $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. * From a422e06989ffad1446b86bb38485209f75d7b0c4 Mon Sep 17 00:00:00 2001 From: Jason Lewis Date: Tue, 18 Dec 2012 19:21:05 +1100 Subject: [PATCH 2/2] Find no longer needs to be defined on the model since the query catches it correctly. Signed-off-by: Jason Lewis --- laravel/database/eloquent/model.php | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/laravel/database/eloquent/model.php b/laravel/database/eloquent/model.php index 2efb964b..433c25ff 100644 --- a/laravel/database/eloquent/model.php +++ b/laravel/database/eloquent/model.php @@ -225,18 +225,6 @@ public static function update($id, $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. * @@ -762,7 +750,7 @@ public function __call($method, $parameters) 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 // keep underscored methods of those methods and intercept calls to them