Fix insert() method for related models.
This commit is contained in:
parent
84bf7d662a
commit
aa341357ec
|
@ -12,12 +12,19 @@ class Has_One_Or_Many extends Relationship {
|
|||
*/
|
||||
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();
|
||||
|
||||
return $this->model->create($attributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a record for the association.
|
||||
|
|
Loading…
Reference in New Issue