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(); - } - } - } } }