Commit eaaac620 authored by Taylor Otwell's avatar Taylor Otwell

Refactoring System\DB\Eloquent.

parent 8c0dfffa
...@@ -75,6 +75,20 @@ abstract class Eloquent { ...@@ -75,6 +75,20 @@ abstract class Eloquent {
*/ */
public $query; 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. * Get the table name for a model.
* *
...@@ -272,12 +286,12 @@ abstract class Eloquent { ...@@ -272,12 +286,12 @@ abstract class Eloquent {
// //
// This is the same convention as has_one and has_many. // 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) return static::make($model)
->select(static::table($model).'.*') ->select(static::table($model).'.*')
->join($this->relating_table, static::table($model).'.id', '=', $this->relating_table.'.'.Str::lower($model).'_id') ->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);
} }
/** /**
......
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