From eaaac620a0b763980b0878638704fd443500f1d9 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 17 Jun 2011 14:47:45 -0700 Subject: [PATCH] Refactoring System\DB\Eloquent. --- system/db/eloquent.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/system/db/eloquent.php b/system/db/eloquent.php index ac3162a6..787f1c2b 100644 --- a/system/db/eloquent.php +++ b/system/db/eloquent.php @@ -75,6 +75,20 @@ abstract class Eloquent { */ public $query; + /** + * Create a new Eloquent model instance. + * + * @param array $attributes + * @return void + */ + public function __construct($attributes = array()) + { + foreach ($attributes as $key => $value) + { + $this->$key = $value; + } + } + /** * Get the table name for a model. * @@ -272,12 +286,12 @@ abstract class Eloquent { // // This is the same convention as has_one and has_many. // ----------------------------------------------------- - $this->relating_key = $this->relating_table.'.'.Str::lower(get_class($this)).'_id'; + $this->relating_key = Str::lower(get_class($this)).'_id'; return static::make($model) ->select(static::table($model).'.*') ->join($this->relating_table, static::table($model).'.id', '=', $this->relating_table.'.'.Str::lower($model).'_id') - ->where($this->relating_key, '=', $this->id); + ->where($this->relating_table.'.'.$this->relating_key, '=', $this->id); } /**