Skip to content

Commit 73d4b0b

Browse files
committed
Merge pull request laravel#1363 from franzliedke/patch-55
Many-to-many sync: always work with arrays
2 parents aa902de + 2d052a3 commit 73d4b0b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

laravel/database/eloquent/relationships/has_many_and_belongs_to.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public function detach($ids)
121121
public function sync($ids)
122122
{
123123
$current = $this->pivot()->lists($this->other_key());
124+
$ids = (array) $ids;
124125

125126
// First we need to attach any of the associated models that are not currently
126127
// in the joining table. We'll spin through the given IDs, checking to see
@@ -140,7 +141,7 @@ public function sync($ids)
140141

141142
if (count($detach) > 0)
142143
{
143-
$this->detach(array_diff($current, $ids));
144+
$this->detach($detach);
144145
}
145146
}
146147

0 commit comments

Comments
 (0)