This project is archived and is in readonly mode.
after_update callback called when cascade destroying an association
-
Neeraj Singh
- Importance changed from to Low
To my knowledge this should not happen
What is this. Can you elaborate?
-
Claudio Poli
I simply assume that an after_update callback should not be triggered on a destroy action.
The Subscription object is being destroyed due to the :dependent option, but not updated.
Yehuda said in IRC that this may be intended, though.
-
Neeraj Singh
- Assigned user set to Yehuda Katz (wycats)
-
Geoff Garside
I've been trying to work around this and noticed that before_destroy isn't called before the association is flushed either, so I can't set an instance variable on my model for the after_update callback to check for to see if its actually being deleted and should therefore not perform its task.
It would be nice if ActiveRecord::Base#destroyed? actually returned true before the associations were flushed, this would help in having after_update return early.
I've also tried looking at after_commit but that doesn't seem to fit my requirements as its not possible to discern if a model has been recently created or not. I should be able to hack something together, but it feels like AR::Base#destroyed? should return true once #destroy has been called, I'd love to hear thoughts on this. Additionally I find it a bit surprising that before_destroy isn't called before the association is flushed, but this could be an ordering issue perhaps.
It is probably worth noting all of my callbacks are in an Observer rather than the model, but I wouldn't have thought that would make a substantial difference with the possible exception of ordering callbacks.
-
Santiago Pastorino
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale
-
Geoffrey Hichborn
I have confirmed that this does indeed occur in the 3-0-6 branch. Running the tests in my rails 3.0.6 branch of my delete_paranoid gem will reveal this:
-
Geoffrey Hichborn
Actually, I just found an issue in my test and confirmed that this works properly in Rails.
https://github.com/phene/rails/tree/update-callbacks-triggered-on-d...