aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/autosave_association.rb
diff options
context:
space:
mode:
authorAnmol Chopra <anmolchopra@rocketbox.in>2017-11-24 17:52:35 +0530
committerAnmol Chopra <anmolchopra@rocketbox.in>2017-11-27 09:41:36 +0530
commitc10152daf948b5bdcf48cda06b9bbddee9e8c398 (patch)
treea793ba191e95f4f08c5d1af86f8739fec92cf2e6 /activerecord/lib/active_record/autosave_association.rb
parenta7d7277f947dcbe31870af9f03a42d56d2b60fcc (diff)
downloadrails-c10152daf948b5bdcf48cda06b9bbddee9e8c398.tar.gz
rails-c10152daf948b5bdcf48cda06b9bbddee9e8c398.tar.bz2
rails-c10152daf948b5bdcf48cda06b9bbddee9e8c398.zip
Inverse instance should not be reloaded during autosave if called in validation
Record saved in save_has_one_association already make call to association.loaded! via record's before_save callback of save_belongs_to_association, but this will reload object if accessed in record's validation.
Diffstat (limited to 'activerecord/lib/active_record/autosave_association.rb')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 6974cf74f6..a1250c3835 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -436,6 +436,9 @@ module ActiveRecord
if (autosave && record.changed_for_autosave?) || new_record? || record_changed?(reflection, record, key)
unless reflection.through_reflection
record[reflection.foreign_key] = key
+ if inverse_reflection = reflection.inverse_of
+ record.association(inverse_reflection.name).loaded!
+ end
end
saved = record.save(validate: !autosave)