Replies: 11 comments
-
I'm curious what the use case would be for dirty attributes in a soft delete operation? Aren't you just calling $foo->delete()? What is being updated? |
Beta Was this translation helpful? Give feedback.
-
Yes, I call ->delete() and in runSoftDelete() I have more changes to the model (ex: deleted_by). |
Beta Was this translation helpful? Give feedback.
-
This can be done without BC break too - return boolean from Currently performDeleteOnModel returns null so it should return false on Model and true on SoftDeletes. SoftDeletes still has to fire the event itself. Not so nice, but an option. |
Beta Was this translation helpful? Give feedback.
-
Converted to discussion as this is a feature request IMO. |
Beta Was this translation helpful? Give feedback.
-
I am hooking in here, as I have a similar issue. In my opinion it seems logical to have the "deleted_at" field dirty on delete. (as well as created_at and updated_at are dirty on create/update events). In the current version no state changes are reported on delete, which is fine in my opinion as long as there is no soft-delete. However, with soft delete enabled it is not logical to have getDirty return an empty array when in reality the deleted_at timestamp changed. I want to make clear that this differs from other requests, that want to combine save() and delete() operations (i.e. #36064 and #18119). I am not requesting an Eloquent core change, changing a model and deleting it should remain two seperate actions. But my intention is to convince you to a uniform behavior across the different model actions. The current workaround for me is to check if deleted_at is still null, but this does not feel "framework native" to me. kind regards |
Beta Was this translation helpful? Give feedback.
-
I am having the same issue I thought deleted_at should be returned when you check for getDirty() attributes. IMO this should not be considered a feature request but a bug |
Beta Was this translation helpful? Give feedback.
-
I have the same issue here, I'm using model events to track changes to model attributes with the I'd argue 'deleted_at' not being returned by the |
Beta Was this translation helpful? Give feedback.
-
+1 I have the same issue. Thanks |
Beta Was this translation helpful? Give feedback.
-
I would also argue that |
Beta Was this translation helpful? Give feedback.
-
Going to add a +1 here as well. Spent a lot of time trying to debug an issue and turns out it was because of this :( |
Beta Was this translation helpful? Give feedback.
-
Have same problem. +1 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
When soft-deleting a model changes are not visible to deleted event handlers as syncOriginal is called before firing the event.
In real and forced delete DB record is deleted, syncOriginal is not needed and everything is ok.
In soft-delete:
Model::delete()
calls$this->performDeleteOnModel()
(goes toSoftDeletes
trait method)SoftDeletes::performDeleteOnModel
callsrunSoftDelete
SoftDeletes::runSoftDelete
updates DB record and calls$this->syncOriginalAttributes
Model::delete()
firesdeleted
eventResult is that in deleted event handlers model
getDirty()
is empty but it should contain at leastdeleted_at
attribute.Proposal:
Make the order similar to update which soft-delete in reality is. (as in
Model::finishSave
)Move
$this->fireModelEvent('deleted', false);
fromModel::delete
to the end ofModel::performDeleteOnModel
and add tosoftDeletes::runSoftDelete
between update and syncOriginalThis way all the changes done in softDelete logic is visible to deleted event handlers.
Note: This creates BC breaks if someone has overwritten
performDeleteOnModel
orrunSoftDelete
in their app.PR or not to PR ?
Beta Was this translation helpful? Give feedback.
All reactions