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

Preserve readonly flag only for readonly association #24099

Merged
merged 1 commit into from
Aug 19, 2016

Conversation

k0kubun
Copy link
Contributor

@k0kubun k0kubun commented Mar 8, 2016

Summary

I fixed a bug in #18097. See #24093 for detail.
In this patch, I made eager-loaded association readonly only when it was specified as readonly.

Fixes #24093

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@@ -1419,6 +1419,24 @@ def test_eager_load_multiple_associations_with_references
assert david.readonly_comments.first.readonly?
end

test "eager-loading non-readonly association" do
# has-one
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and squashed in k0kubun@7eaa6dd

@k0kubun k0kubun force-pushed the preserve-readonly branch 2 times, most recently from ffd4b4b to 7eaa6dd Compare March 8, 2016 04:24
join_scope = join_scope.instance_exec(nil, &node.reflection.scope) if node.reflection.scope
if join_scope.values[:readonly]
model.readonly!
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is reaching into a lot of internals of other objects. Can you refactor this to something a bit more contained?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this? k0kubun@198b285

@k0kubun k0kubun force-pushed the preserve-readonly branch 2 times, most recently from b258136 to 198b285 Compare March 9, 2016 17:15
@bquorning
Copy link
Contributor

@sgrif Do you have time for a 2nd review? In my opinon, this (and #24093) should be added to the 5.0.0 milestone.

@sgrif
Copy link
Contributor

sgrif commented Mar 20, 2016

We are well beyond the feature freeze for the 5.0 milestone. This bug isn't critical enough to mark as a release blocker. It will be resolved in 5.0l.1

@bquorning
Copy link
Contributor

@jeremy Do you want to add this PR to the 5.0.1 milestone, as per Sean’s comment above?

@maclover7
Copy link
Contributor

Solves #25835 as well.

@@ -272,7 +272,9 @@ def construct(ar_parent, parent, row, rs, seen, model_cache, aliases)
construct(model, node, row, rs, seen, model_cache, aliases)
else
model = construct_model(ar_parent, node, row, model_cache, id, aliases)
model.readonly!
if node.reflection.scope_for(node.base_klass).values[:readonly]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to catch it. Fixed so in 411e459.

@johanlunds
Copy link
Contributor

Just FYI, to help someone else running into this in the meantime: our workaround was to .reload the record before updating it.

@rafaelfranca rafaelfranca merged commit 411e459 into rails:master Aug 19, 2016
rafaelfranca added a commit that referenced this pull request Aug 19, 2016
Preserve readonly flag only for readonly association
rafaelfranca added a commit that referenced this pull request Aug 19, 2016
Preserve readonly flag only for readonly association
@rafaelfranca
Copy link
Member

Backported in 3cffae5

@k0kubun k0kubun deleted the preserve-readonly branch August 19, 2016 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Eager loaded belongs_to associations are always readonly
8 participants