Skip to content

Commit

Permalink
Get all IDs when detaching without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
joostbaptist authored and fico7489 committed Feb 22, 2018
1 parent 0e8470c commit d7608aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Relations/BelongsToManyCustom.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function attach($ids, array $attributes = [], $touch = true)
*/
public function detach($ids = null, $touch = true)
{
if (is_null($ids)) {
$ids = $this->query->pluck($this->query->qualifyColumn('id'))->toArray();
}

list($idsOnly) = $this->getIdsWithAttributes($ids);

$this->parent->fireModelEvent('pivotDetaching', true, $this->getRelationName(), $idsOnly);
Expand Down
2 changes: 1 addition & 1 deletion tests/PivotEventTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function test_detach_null()

$this->assertEquals(0, \DB::table('role_user')->count());
$this->check_events(['eloquent.pivotDetaching: ' . User::class, 'eloquent.pivotDetached: ' . User::class]);
$this->check_variables(0, []);
$this->check_variables(0, [1, 2, 3]);
}

public function test_update()
Expand Down

0 comments on commit d7608aa

Please sign in to comment.