You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An early return like return unless autosave = reflection.options[:autosave] is solving the issue on my local. It seems we dont need to load relation if autosave option is falsy. I'm willing to open a pr if this solution seems plausible to you.
EDIT: We cannot add an early return here as has_one relation wants to save new records by default.
maybe we can add an early return like the one used in save_belongs_to_association 👇 (sth like return unless association && association.loaded?)
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails team are limited, and so we are asking for your help.
If you can still reproduce this error on the 7-0-stable branch or on main, please reply with all of the information you have about it in order to keep the issue open.
Thank you for all your contributions.
Steps to reproduce
foo.association(:bar)
foo.save!
Expected behavior
with_association_call should not fire
SELECT "bars".* FROM "bars" WHERE "bars"."foo_id" = ? LIMIT ?
queryActual behavior
with_association_call fires the query
System configuration
Rails version: 7.0.0.alpha2
Ruby version: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
Some ideas about what happens here
I believe the error stems from the implementation of the below
save_has_one_association
method.rails/activerecord/lib/active_record/autosave_association.rb
Lines 435 to 461 in 1268b9a
An early return likereturn unless autosave = reflection.options[:autosave]
is solving the issue on my local. It seems we dont need to load relation ifautosave
option is falsy. I'm willing to open a pr if this solution seems plausible to you.EDIT: We cannot add an early return here as has_one relation wants to save new records by default.
maybe we can add an early return like the one used in save_belongs_to_association 👇 (sth like
return unless association && association.loaded?
)rails/activerecord/lib/active_record/autosave_association.rb
Line 481 in 1268b9a
Note: I was not able to reproduce this for has_many and belongs_to relations if that helps.
Also, probably related to #42637. Adding an early return seems to solve that issue as well.
The text was updated successfully, but these errors were encountered: