aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-20 20:42:46 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-20 20:42:46 -0300
commit26931eb32082b3468dc12df59c4041841f64c510 (patch)
tree72f40802ecc0cf9f2cad45c1b1eb7bc2133cd647 /activerecord/lib
parent5508a3e5ca05d4c43232868f40ebd726d251eeac (diff)
downloadrails-26931eb32082b3468dc12df59c4041841f64c510.tar.gz
rails-26931eb32082b3468dc12df59c4041841f64c510.tar.bz2
rails-26931eb32082b3468dc12df59c4041841f64c510.zip
Revert "Revert "Merge pull request #8313 from alan/only_save_changed_has_one_objects""
This reverts commit e94e6c27af495a2460c811bb506459f1428dec6b. Conflicts: activerecord/CHANGELOG.md The original commit was reverted only to be safe since #14407 were reported. We don't have any proof we added a regression with the original commit so reverting it now will give us more problem. Closes #14407
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 80cf7572df..1a4d2957ec 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -381,15 +381,16 @@ module ActiveRecord
def save_has_one_association(reflection)
association = association_instance_get(reflection.name)
record = association && association.load_target
+
if record && !record.destroyed?
autosave = reflection.options[:autosave]
if autosave && record.marked_for_destruction?
record.destroy
- else
+ elsif autosave != false
key = reflection.options[:primary_key] ? send(reflection.options[:primary_key]) : id
- if autosave != false && (autosave || new_record? || record_changed?(reflection, record, key))
+ if (autosave && record.changed_for_autosave?) || new_record? || record_changed?(reflection, record, key)
unless reflection.through_reflection
record[reflection.foreign_key] = key
end