-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
The order of macro-style methods could be problematic for before_destroy callbacks #77
Comments
👍 |
Just got bitten by this. The behaviour is documented in "Ordering callbacks": http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html ... but I still think it is broken behaviour. |
@xaviershay you mean broken in Rails? I think I'd agree with that. |
correct, it's a non-obvious dependency between apparently unrelated declarative statements. |
@xaviershay @daviddavis I also agree that's broken in Rails. Maybe this should be discussed with someone on the Rails team? |
Just got hit by this too. HUGE gotchya. ( For now I'm using |
@smudge Nice workaround! I hope rails change its behavior soon. |
I opened a temporary fix in #110 |
Due to rails/rails#3458, we may want to consider putting callbacks before associations (or maybe just before_destroy?). Take the following example.
This won't work as expected. Instead it will destroy a user's roles whenever destroy is called regardless if the user actually gets deleted. The fix is to list the callback first:
It might be a best practice to just list callbacks before associations--or just before_destroy?
EDIT: Thanks to @smudge (see below), here's a better workaround:
The text was updated successfully, but these errors were encountered: