Added related model updating from belongs_to relationship.

This commit is contained in:
Taylor Otwell
2012-03-17 23:14:01 -05:00
parent 68b4e55336
commit fcff36a0ac
4 changed files with 42 additions and 5 deletions

View File

@@ -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);
}
}