Browse Source

Fix insert() method for related models.

Franz Liedke 12 years ago
parent
commit
aa341357ec
1 changed files with 11 additions and 4 deletions
  1. 11 4
      laravel/database/eloquent/relationships/has_one_or_many.php

+ 11 - 4
laravel/database/eloquent/relationships/has_one_or_many.php

@@ -12,11 +12,18 @@ class Has_One_Or_Many extends Relationship {
 	 */
 	 */
 	public function insert($attributes)
 	public function insert($attributes)
 	{
 	{
-		$attributes = ($attributes instanceof Model) ? $attributes->attributes : $attributes;
-
-		$attributes[$this->foreign_key()] = $this->base->get_key();
+		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);
+			return $this->model->create($attributes);
+		}
 	}
 	}
 
 
 	/**
 	/**