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
Read has_one
through association target from memory for new records
#42575
base: main
Are you sure you want to change the base?
Conversation
58f9719
to
a533a19
Compare
Possibly a stupid question, but does it make sense to favour the database over what we have in memory? Thinking about my test from #42387, if I adapt it to the following:
If we load from the database in the |
Honestly I didn't run the above piece of code but I think it should use the DB already in such situation because we set the FK: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/associations/association.rb#L281 This PR handles the case when the associations were not already persisted without impacting the already existing behaviour. |
When reading an `has_one` through association for a new record and loading from DB is not possible retrieves the association target from the in memory through association. Fixes rails#42387
a533a19
to
bef7d67
Compare
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
still relevant |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
ping |
@intrip nice PR 👍. I think this is causing an issue for me. Using a |
@mpmenne I don't understand how this could cause you issue since is not merged yet: are you using this patch in your codebase? If so could you please provide me a code example? |
Summary
When reading an
has_one
through association for a new record and loading from DB is not possible retrieves the association target from the in memory through association.Fixes #42387