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

Fixed Exception if Cascaded Models are not SoftDeleted #141

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 this triggers also an update() somewhere, and because updated query withTrashed(), the transaction fails.

With this rather quick fix, withTrashed() should only be called if the model is SoftDeletable.

kohlerdominik commented 1 year ago

Nevermind, a fix like this does not work because of it does not consider the heavy use of Laravels forwardsCalls