Browse Source

Fixing a few things in Eloquent 2.

Taylor Otwell 12 years ago
parent
commit
b6615ddbee

+ 28 - 0
laravel/database/eloquent/model.php

@@ -547,6 +547,34 @@ abstract class Model {
 		$this->{"set_{$key}"}($value);
 	}
 
+	/**
+	 * Determine if an attribute exists on the model.
+	 *
+	 * @param  string  $key
+	 * @return bool
+	 */
+	public function __isset($key)
+	{
+		foreach (array('attributes', 'relationships') as $source)
+		{
+			if (array_key_exists($key, $this->$source)) return true;
+		}
+	}
+
+	/**
+	 * Remove an attribute from the model.
+	 *
+	 * @param  string  $key
+	 * @return void
+	 */
+	public function __unset($key)
+	{
+		foreach (array('attributes', 'relationships') as $source)
+		{
+			unset($this->$source[$key]);
+		}
+	}
+
 	/**
 	 * Handle dynamic method calls on the model.
 	 *

+ 1 - 1
laravel/database/eloquent/relationships/has_many_and_belongs_to.php

@@ -110,7 +110,7 @@ class Has_Many_And_Belongs_To extends Relationship {
 		// the developer to not worry about maintaining the join table.
 		if ($model instanceof Model)
 		{
-			$joining = array_merge($this->join_record($id), $joining);
+			$joining = array_merge($this->join_record($model->get_key()), $joining);
 
 			$result = $this->insert_joining($joining);
 		}