Askedio / laravel-soft-cascade

Cascade Delete & Restore when using Laravel SoftDeletes
https://medium.com/asked-io/cascading-softdeletes-with-laravel-5-a1a9335a5b4d
MIT License
705 stars 63 forks source link

Support CascadeDeletes of models without SoftDelete #143

Closed kohlerdominik closed 1 year ago

kohlerdominik commented 1 year ago

I found an issue, when a SoftDeleted model should delete a NotSoftDeleted model. The CascadeQueryListener triggers an update, and tries to update the deleted_at-columns, which does only exist, if the model uses SoftDeletes.

My use-case is an edge-case, but still valid, I think. I have this model structure:

Group(SoftDeleted) > Device(SoftDeleted) > Logs

Logs are not SoftDeleted, as they are very short-lived anyway. They have no SoftDelete, and are lost if the Device is deleted. This works without issues.

If the Group is deleted, it does CascadeDelete the Device, which then should CascadeDelete the Logs (hard delete). But with the current code, subsequent deletes are executed as update(['deleted_at' => '...'])-calls, which does not work on models without SoftDelete.


This fix changes the behaviour of the detection in the CascadeQueryListener for better differentiation between delete() and update()-calls, and should resolve this issue.

kohlerdominik commented 1 year ago

Ping @maguilar92

gcphost commented 1 year ago

Please resolve the style errors: https://github.styleci.io/analyses/16NJlj

kohlerdominik commented 1 year ago

Thanks for the feedback. Fixed.

gcphost commented 1 year ago

Looks good to me. Thanks for your contribution. I'm surprised I didn't run into this myself, we must have soft-deleted everything, even logs!