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 587e504cdd9..cc921861b02 100644 --- a/laravel/database/eloquent/relationships/has_many_and_belongs_to.php +++ b/laravel/database/eloquent/relationships/has_many_and_belongs_to.php @@ -85,12 +85,14 @@ public function results() /** * Insert a new record into the joining table of the association. * - * @param int $id - * @param array $joining + * @param Model|int $id + * @param array $attributes * @return bool */ public function attach($id, $attributes = array()) { + if ($id instanceof Model) $id = $id->get_key(); + $joining = array_merge($this->join_record($id), $attributes); return $this->insert_joining($joining); @@ -99,12 +101,13 @@ public function attach($id, $attributes = array()) /** * Detach a record from the joining table of the association. * - * @param int $ids + * @param array|Model|int $ids * @return bool */ public function detach($ids) { - if ( ! is_array($ids)) $ids = array($ids); + if ($ids instanceof Model) $ids = array($ids->get_key()); + elseif ( ! is_array($ids)) $ids = array($ids); return $this->pivot()->where_in($this->other_key(), $ids)->delete(); }