diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-20 20:42:46 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-20 20:42:46 -0300 |
commit | 26931eb32082b3468dc12df59c4041841f64c510 (patch) | |
tree | 72f40802ecc0cf9f2cad45c1b1eb7bc2133cd647 /activerecord/lib/active_record | |
parent | 5508a3e5ca05d4c43232868f40ebd726d251eeac (diff) | |
download | rails-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/active_record')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 5 |
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 |