Refactoring System\DB\Eloquent.

This commit is contained in:
Taylor Otwell 2011-06-17 14:47:45 -07:00
parent 8c0dfffa34
commit eaaac620a0
1 changed files with 16 additions and 2 deletions

View File

@ -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 @@ public function has_and_belongs_to_many($model, $table = null)
//
// 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);
}
/**