Added related model updating from belongs_to relationship.
This commit is contained in:
@@ -12,6 +12,17 @@ class Belongs_To extends Relationship {
|
||||
return parent::first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the parent model of the relationship.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return int
|
||||
*/
|
||||
public function update($attributes)
|
||||
{
|
||||
return $this->model->update($this->foreign_value(), $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the proper constraints on the relationship table.
|
||||
*
|
||||
@@ -19,9 +30,7 @@ class Belongs_To extends Relationship {
|
||||
*/
|
||||
protected function constrain()
|
||||
{
|
||||
$foreign = $this->base->get_attribute($this->foreign);
|
||||
|
||||
$this->table->where($this->base->key(), '=', $foreign);
|
||||
$this->table->where($this->base->key(), '=', $this->foreign_value());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,4 +89,14 @@ class Belongs_To extends Relationship {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the foreign key from the base model.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function foreign_value()
|
||||
{
|
||||
return $this->base->get_attribute($this->foreign);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user