From 3770e942f5ce486ca7210b44e845e6d5dc599e0b Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Thu, 14 Sep 2023 09:05:01 -0400 Subject: [PATCH] verify the relation "detach" option --- src/Database/Model.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/Database/Model.php b/src/Database/Model.php index 2c667e37..23b36ec6 100644 --- a/src/Database/Model.php +++ b/src/Database/Model.php @@ -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 { @@ -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(); - } - } - } } }