laravel-cascade-soft-deletes
laravel-cascade-soft-deletes copied to clipboard
Do pivot records get hard deleted?
I am reading through the code and it seems like pivot records in many to many relationships get hard deleted
https://github.com/michaeldyrynda/laravel-cascade-soft-deletes/blob/main/src/CascadeSoftDeletes.php#L69
isset($model->pivot) ? $model->pivot->{$delete}() : $model->{$delete}();
Is this intended?
@mvynhb They don't get force deleted, if that is what you are referring to.
One line above the one you mentioned, the $delete
method name is set tot either forceDelete
or delete
, depending on the model's setting.
So this should deliver the intended outcome.
@mathiasonea There are a few points here
- The pivot table is not defined as a model and does not implement SoftDeletes
- The pivot table might not have a deleted_at
- Even if you delete the pivot records based on the logic above it doesn't attempt to soft delete its related models. So it does disconnect the pivot table from its relationships but the related tables are not soft deleted.
Or maybe I am missing something obvious?
From memory, yes, the pivot record is deleted but not the related records of the pivot