New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callback after_rollback on :destroy seems not be working correclty #7640
Comments
Looks like a chunk of the offending behavior is here: https://github.com/rails/rails/blob/master/activerecord/lib/active_record/transactions.rb#L372 The issue is that, by the time I'm not sure if this behavior is correct, but I'm also not sure what could be done to make it work correctly. Almost by definition, the records are supposed to be back in their previous state after the rollback... |
As @al2o3cr pointed out
How about raising an exception that |
This issue has been automatically marked as stale because it has not been commented on for at least The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the Thank you for all your contributions. |
This issue has been automatically closed because of inactivity. If you can still reproduce this error on the Thank you for all your contributions. |
Ran in to the same problem today :(. Does anybody have a workaround? If I ran the |
Here's my current workaround: class Enrollment < ActiveRecord::Base
# Callbacks
# ---------------------------------------------------------
before_destroy :cancel_destroy
after_rollback :set_as_inactive
private
def set_as_inactive
if @destroy_attempted
write_attribute(:active, false)
@destroy_attempted = false
save!
end
end
# Enrollments are never actually deleted - they are just set to inactive.
def cancel_destroy
@destroy_attempted = true
false
end
end By the way, I would love it if somebody pointed out anything wrong or potentially dangerous about this. |
@KurtRMueller - a solution like the one https://github.com/radar/paranoia/blob/rails4/lib/paranoia.rb#L58 |
@al2o3cr - oh, nice! Thanks for heads up. |
Apparently using the callback :after_rollback on :destroy action is calling the update method instead of destroy. Example:
Table
Model
Rails Console
or this behavior is correct?
The text was updated successfully, but these errors were encountered: