before_destroy callback fires after the record has already been marked as deleted
ahorner opened this issue · comments
Andrew Horner commented
This problem rears its ugly head when you have a before_destroy
callback that attempts to navigate a record's associations or find a deleted record.
The set_deleted_at
method performs a save!
before the callbacks are ever triggered, so the record is marked as deleted before the callbacks fire, which is inconsistent with the expected order of events:
before_destroy
- record is destroyed
after_destroy
This issue is particularly noticeable when you have a default_scope
applied to a model.