diff --git a/src/Database/Model.php b/src/Database/Model.php index db68736c7..8ebfc2c5b 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,11 @@ protected function performDeleteOnRelations() continue; } + // Attempt to load the related record(s) + 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..82953eb2b 100644 --- a/src/Database/Traits/SoftDelete.php +++ b/src/Database/Traits/SoftDelete.php @@ -115,10 +115,11 @@ 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)) { + // Attempt to load the related record(s) + if (!$relation = $this->{$name}) { continue; } if (in_array($type, ['belongsToMany', 'morphToMany', 'morphedByMany'])) {