laravel-cascade-soft-deletes icon indicating copy to clipboard operation
laravel-cascade-soft-deletes copied to clipboard

Do pivot records get hard deleted?

Open mvynhb opened this issue 1 year ago • 2 comments

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 avatar Feb 25 '23 02:02 mvynhb

@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 avatar Mar 22 '23 08:03 mathiasonea

@mathiasonea There are a few points here

  1. The pivot table is not defined as a model and does not implement SoftDeletes
  2. The pivot table might not have a deleted_at
  3. 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?

mvynhb avatar Mar 22 '23 13:03 mvynhb

From memory, yes, the pivot record is deleted but not the related records of the pivot

michaeldyrynda avatar Mar 18 '24 23:03 michaeldyrynda