Commit 73d4b0b2 authored by Jason Lewis's avatar Jason Lewis

Merge pull request #1363 from franzliedke/patch-55

Many-to-many sync: always work with arrays
parents aa902def 2d052a32
...@@ -121,6 +121,7 @@ class Has_Many_And_Belongs_To extends Relationship { ...@@ -121,6 +121,7 @@ class Has_Many_And_Belongs_To extends Relationship {
public function sync($ids) public function sync($ids)
{ {
$current = $this->pivot()->lists($this->other_key()); $current = $this->pivot()->lists($this->other_key());
$ids = (array) $ids;
// First we need to attach any of the associated models that are not currently // 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 // in the joining table. We'll spin through the given IDs, checking to see
...@@ -140,7 +141,7 @@ class Has_Many_And_Belongs_To extends Relationship { ...@@ -140,7 +141,7 @@ class Has_Many_And_Belongs_To extends Relationship {
if (count($detach) > 0) if (count($detach) > 0)
{ {
$this->detach(array_diff($current, $ids)); $this->detach($detach);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment