-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
doc(active_record): adding more examples about scope control #50342
doc(active_record): adding more examples about scope control #50342
Conversation
60269e1
to
0634bc7
Compare
Thank you very much @p8 for the feedback, I have already made the suggested changes. |
guides/source/association_basics.md
Outdated
@@ -788,7 +788,30 @@ module MyApplication | |||
end | |||
``` | |||
|
|||
This will work fine, because both the `Supplier` and the `Account` class are defined within the same scope. But the following will _not_ work, because `Supplier` and `Account` are defined in different scopes: | |||
This will work fine, because both the `Supplier` and the `Account` class are defined within the same scope (`MyApplication::Business`). This organization allows structuring models into folders based on their scope: |
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.
A small change to maybe make things a bit clearer what the advantage is:
This will work fine, because both the `Supplier` and the `Account` class are defined within the same scope (`MyApplication::Business`). This organization allows structuring models into folders based on their scope: | |
This will work fine, because both the `Supplier` and the `Account` class are defined within the same scope (`MyApplication::Business`). This organization allows structuring models into folders based on their scope, without having to explicitly add the scope to every association: |
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.
Done! 😄
0634bc7
to
c430cc3
Compare
Thanks @JohnAnon9771 ! |
Motivation / Background
In the rails contributors discord, there was a discussion in the past about a Rails behavior that is somewhat unknown to Rails newbies (I am included in that list) where it showed that Rails can identify which relationship you define according to the scope of the model.
I'm opening this PR for opinions on how this can be documented, as it seems to be something very interesting about Rails and which is only noticed if you have the correct intuition that Rails can do this.
rails/activerecord/lib/active_record/inheritance.rb
Lines 241 to 244 in c9cdd80
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]