diff --git a/laravel/database/eloquent/relationships/has_one_or_many.php b/laravel/database/eloquent/relationships/has_one_or_many.php index a8268de6..7dd453b3 100644 --- a/laravel/database/eloquent/relationships/has_one_or_many.php +++ b/laravel/database/eloquent/relationships/has_one_or_many.php @@ -12,11 +12,18 @@ 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(); - $attributes[$this->foreign_key()] = $this->base->get_key(); - - return $this->model->create($attributes); + return $this->model->create($attributes); + } } /**