Skip to content
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

Merged
merged 1 commit into from Mar 12, 2019

Conversation

Rodrigora
Copy link
Contributor

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

@rails-bot rails-bot bot added the docs label Mar 8, 2019
@Rodrigora Rodrigora changed the title Add note about has_many associations callbacks [ci skip] Add note about has_many associations callbacks Mar 8, 2019
Add a note explaining when the has_many associations callbacks will be called or not.
@Rodrigora
Copy link
Contributor Author

Thanks for the review @vipulnsward . It is updated

@vipulnsward vipulnsward merged commit 7ed1302 into rails:master Mar 12, 2019
@vipulnsward
Copy link
Member

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:
Copy link
Contributor

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?

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants