Skip to content

Commit

Permalink
verify the relation "detach" option
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Sep 14, 2023
1 parent 97ff392 commit 3770e94
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/Database/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,9 @@ protected function performDeleteOnRelations()
}

if (in_array($type, ['belongsToMany', 'morphToMany', 'morphedByMany'])) {
if (!Arr::get($options, 'detach', true)) {
continue;
}
// we want to remove the pivot record, not the actual relation record
$relation()->detach();
} else {
Expand All @@ -1029,17 +1032,6 @@ protected function performDeleteOnRelations()
}
}
}

/*
* Belongs-To-Many should clean up after itself always
*/
if ($type == 'belongsToMany') {
foreach ($relations as $name => $options) {
if (Arr::get($options, 'detach', true)) {
$this->{$name}()->detach();
}
}
}
}
}

Expand Down

0 comments on commit 3770e94

Please sign in to comment.