From b6615ddbee8bbd41751d930616cddf777100a221 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 22 Mar 2012 11:00:13 -0500 Subject: [PATCH] Fixing a few things in Eloquent 2. --- laravel/database/eloquent/model.php | 28 +++++++++++++++++++ .../relationships/has_many_and_belongs_to.php | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/laravel/database/eloquent/model.php b/laravel/database/eloquent/model.php index 45c8c3ca..c726be47 100644 --- a/laravel/database/eloquent/model.php +++ b/laravel/database/eloquent/model.php @@ -547,6 +547,34 @@ public function __set($key, $value) $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. * diff --git a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php index bfc17dd0..a90abb99 100644 --- a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php +++ b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php @@ -110,7 +110,7 @@ public function insert($attributes, $joining = array()) // 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); }