Commit aa341357 authored by Franz Liedke's avatar Franz Liedke

Fix insert() method for related models.

parent 84bf7d66
...@@ -12,12 +12,19 @@ class Has_One_Or_Many extends Relationship { ...@@ -12,12 +12,19 @@ class Has_One_Or_Many extends Relationship {
*/ */
public function insert($attributes) public function insert($attributes)
{ {
$attributes = ($attributes instanceof Model) ? $attributes->attributes : $attributes; if ($attributes instanceof Model)
{
$attributes->set_attribute($this->foreign_key(), $this->base->get_key());
return $attributes->save();
}
else
{
$attributes[$this->foreign_key()] = $this->base->get_key(); $attributes[$this->foreign_key()] = $this->base->get_key();
return $this->model->create($attributes); return $this->model->create($attributes);
} }
}
/** /**
* Update a record for the association. * Update a record for the association.
......
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