Merge pull request #1363 from franzliedke/patch-55

Many-to-many sync: always work with arrays
This commit is contained in:
Jason Lewis 2012-10-20 07:15:06 -07:00
commit 73d4b0b2a1
1 changed files with 2 additions and 1 deletions

View File

@ -121,6 +121,7 @@ public function detach($ids)
public function sync($ids)
{
$current = $this->pivot()->lists($this->other_key());
$ids = (array) $ids;
// First we need to attach any of the associated models that are not currently
// in the joining table. We'll spin through the given IDs, checking to see
@ -140,7 +141,7 @@ public function sync($ids)
if (count($detach) > 0)
{
$this->detach(array_diff($current, $ids));
$this->detach($detach);
}
}