-
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
eager_load
preserves readonly flag for associations
#18097
Conversation
623ef1d
to
fcd0fb7
Compare
fcd0fb7
to
068160b
Compare
Because the provided gist in #15853 is testing belongs_to, I added a test for it. |
`eager_load` preserves readonly flag for associations
Thank you @k0kubun ! |
@@ -1340,6 +1339,10 @@ def test_deep_including_through_habtm | |||
# has-many :through | |||
david = Author.where(id: "1").eager_load(:readonly_comments).first! | |||
assert david.readonly_comments.first.readonly? | |||
|
|||
# belongs_to | |||
post = Post.where(id: "1").eager_load(:author).first! |
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.
Sorry for commenting on an old PR, but I just don’t understand this change. The association is defined on Post
as belongs_to :author
– no readonly
option defined. So why does it need to be readonly after eager loading?
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.
While I can't remember this problem well now, I think this behavior is not related to readonly
option of belongs_to
. At least joins
was such a behavior and I unified them. I guess it is limited as readonly because the aim of eager loading is not writing but just reading.
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 seems that joins
doesn’t make the association readonly
, while eager_load
does. I’ve opened a bug #24093.
Closes #15853
I changed
join_dependency
to pass skipped test in 5706d29.