Allow passing in a model instance to relationship insert / update methods.

This commit is contained in:
Taylor Otwell
2012-03-20 09:03:31 -05:00
parent e540fd3b6d
commit 079400ff3d
3 changed files with 17 additions and 8 deletions

View File

@@ -7,11 +7,13 @@ class Has_One_Or_Many extends Relationship {
/**
* Insert a new record for the association.
*
* @param array $attributes
* @param Model|array $attributes
* @return bool
*/
public function insert($attributes)
{
$attributes = ($attributes instanceof Model) ? $attributes->attributes : $attributes;
$attributes[$this->foreign_key()] = $this->base->get_key();
return $this->model->create($attributes);