Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6331b3a

Browse files
committed
Merge pull request laravel#724 from AndreasHeiberg/bug-sync-uniquenesss-constraint-conflicts
Detach before attach to prevent uniqueness constraint conflicts
2 parents 8f89565 + b95e4e4 commit 6331b3a

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,6 @@ public function sync(array $ids)
398398

399399
$records = $this->formatSyncList($ids);
400400

401-
$this->attachNew($records, $current);
402-
403401
$detach = array_diff($current, array_keys($records));
404402

405403
// Next, we will take the differences of the currents and given IDs and detach
@@ -409,6 +407,8 @@ public function sync(array $ids)
409407
{
410408
$this->detach($detach);
411409
}
410+
411+
$this->attachNew($records, $current);
412412
}
413413

414414
/**

0 commit comments

Comments
 (0)