Skip to content

Commit aa34135

Browse files
committed
Fix insert() method for related models.
1 parent 84bf7d6 commit aa34135

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

laravel/database/eloquent/relationships/has_one_or_many.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ class Has_One_Or_Many extends Relationship {
1212
*/
1313
public function insert($attributes)
1414
{
15-
$attributes = ($attributes instanceof Model) ? $attributes->attributes : $attributes;
16-
17-
$attributes[$this->foreign_key()] = $this->base->get_key();
15+
if ($attributes instanceof Model)
16+
{
17+
$attributes->set_attribute($this->foreign_key(), $this->base->get_key());
18+
19+
return $attributes->save();
20+
}
21+
else
22+
{
23+
$attributes[$this->foreign_key()] = $this->base->get_key();
1824

19-
return $this->model->create($attributes);
25+
return $this->model->create($attributes);
26+
}
2027
}
2128

2229
/**

0 commit comments

Comments
 (0)