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
Add note about has_many associations callbacks #35530
Conversation
Add a note explaining when the has_many associations callbacks will be called or not.
Thanks for the review @vipulnsward . It is updated |
Thanks! |
@@ -2350,6 +2350,17 @@ end | |||
|
|||
If a `before_add` callback throws an exception, the object does not get added to the collection. Similarly, if a `before_remove` callback throws an exception, the object does not get removed from the collection. | |||
|
|||
NOTE: These callbacks are called only when the associated objects are added or removed through the association collection: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vipulnsward : remove through the associated
sounds little incorrect to me. Maybe we could say removed from the association collection.
Changes:
through
->from
- Sentence should end with period here
Does that sound correct to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's correct as is. The idea is to communicate that adds/removals must go through the has_many
accessor.
Summary
Add a note explaining when the has_many associations callbacks will be called or not.
Other Information
The documented behaviour seems to cause some confusion for some people (including myself).
https://www.google.com/search?q=has_many+callbacks+not+working&rlz=1C5CHFA_enIE796IE796&oq=has_many+callbacks+not+working&aqs=chrome..69i57.8047j0j7&sourceid=chrome&ie=UTF-8