From 5ae215c0bf1e91a006d7362ec9a161a6344839ff Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Tue, 17 Oct 2023 23:30:07 -0400 Subject: [PATCH 1/3] restore previous tests order --- src/Database/Model.php | 8 ++++---- src/Database/Traits/SoftDelete.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Database/Model.php b/src/Database/Model.php index db68736c7..371441088 100644 --- a/src/Database/Model.php +++ b/src/Database/Model.php @@ -1009,10 +1009,6 @@ protected function performDeleteOnRelations() * Hard 'delete' definition */ foreach ($relations as $name => $options) { - if (!$relation = $this->{$name}) { - continue; - } - if (in_array($type, ['belongsToMany', 'morphToMany', 'morphedByMany'])) { // we want to remove the pivot record, not the actual relation record if (Arr::get($options, 'detach', true)) { @@ -1026,6 +1022,10 @@ protected function performDeleteOnRelations() continue; } + if (!$relation = $this->{$name}) { + continue; + } + if ($relation instanceof EloquentModel) { $relation->forceDelete(); } elseif ($relation instanceof CollectionBase) { diff --git a/src/Database/Traits/SoftDelete.php b/src/Database/Traits/SoftDelete.php index fc913b8e8..f97aaffd7 100644 --- a/src/Database/Traits/SoftDelete.php +++ b/src/Database/Traits/SoftDelete.php @@ -115,10 +115,10 @@ protected function performSoftDeleteOnRelations() $definitions = $this->getRelationDefinitions(); foreach ($definitions as $type => $relations) { foreach ($relations as $name => $options) { - if (!$relation = $this->{$name}) { + if (!array_get($options, 'softDelete', false)) { continue; } - if (!array_get($options, 'softDelete', false)) { + if (!$relation = $this->{$name}) { continue; } if (in_array($type, ['belongsToMany', 'morphToMany', 'morphedByMany'])) { From d1c2fe157789fed088e5d88433214d784f63902b Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Thu, 19 Oct 2023 10:05:06 -0600 Subject: [PATCH 2/3] Update src/Database/Model.php --- src/Database/Model.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Database/Model.php b/src/Database/Model.php index 371441088..8ebfc2c5b 100644 --- a/src/Database/Model.php +++ b/src/Database/Model.php @@ -1022,6 +1022,7 @@ protected function performDeleteOnRelations() continue; } + // Attempt to load the related record(s) if (!$relation = $this->{$name}) { continue; } From c2d402a62eadc93f315f39971b723a8856cdf7b8 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Thu, 19 Oct 2023 10:05:22 -0600 Subject: [PATCH 3/3] Update src/Database/Traits/SoftDelete.php --- src/Database/Traits/SoftDelete.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Database/Traits/SoftDelete.php b/src/Database/Traits/SoftDelete.php index f97aaffd7..82953eb2b 100644 --- a/src/Database/Traits/SoftDelete.php +++ b/src/Database/Traits/SoftDelete.php @@ -118,6 +118,7 @@ protected function performSoftDeleteOnRelations() if (!array_get($options, 'softDelete', false)) { continue; } + // Attempt to load the related record(s) if (!$relation = $this->{$name}) { continue; }