Refactoring Eloquent.
This commit is contained in:
parent
8b1fe5920b
commit
c4eb994fbc
|
@ -274,10 +274,13 @@ public function has_and_belongs_to_many($model, $table = null)
|
||||||
|
|
||||||
$this->relating_key = strtolower(get_class($this)).'_id';
|
$this->relating_key = strtolower(get_class($this)).'_id';
|
||||||
|
|
||||||
return static::make($model)
|
$relationship = static::make($model);
|
||||||
->select(array(static::table($model).'.*'))
|
|
||||||
->join($this->relating_table, static::table($model).'.id', '=', $this->relating_table.'.'.strtolower($model).'_id')
|
$relationship->select(array(static::table($model).'.*'));
|
||||||
->where($this->relating_table.'.'.$this->relating_key, '=', $this->id);
|
$relationship->join($this->relating_table, static::table($model).'.id', '=', $this->relating_table.'.'.strtolower($model).'_id');
|
||||||
|
$relationship->where($this->relating_table.'.'.$this->relating_key, '=', $this->id);
|
||||||
|
|
||||||
|
return $relationship;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -366,9 +369,12 @@ public function __get($key)
|
||||||
{
|
{
|
||||||
$model = $this->$key();
|
$model = $this->$key();
|
||||||
|
|
||||||
return ($this->relating == 'has_one' or $this->relating == 'belongs_to')
|
if (in_array($this->relating, array('has_one', 'belongs_to')))
|
||||||
? $this->ignore[$key] = $model->first()
|
{
|
||||||
: $this->ignore[$key] = $model->get();
|
return $this->ignore[$key] = $model->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->ignore[$key] = $model->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (array_key_exists($key, $this->attributes)) ? $this->attributes[$key] : null;
|
return (array_key_exists($key, $this->attributes)) ? $this->attributes[$key] : null;
|
||||||
|
|
Loading…
Reference in New Issue