aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/autosave_association.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-03-25 15:09:48 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-03-25 15:09:48 -0300
commite94e6c27af495a2460c811bb506459f1428dec6b (patch)
tree17d01f309bd409c023b181b8dbcbfa390df5d350 /activerecord/lib/active_record/autosave_association.rb
parent9a976ab5756371dd434adda2ff01af3a83d0f63c (diff)
downloadrails-e94e6c27af495a2460c811bb506459f1428dec6b.tar.gz
rails-e94e6c27af495a2460c811bb506459f1428dec6b.tar.bz2
rails-e94e6c27af495a2460c811bb506459f1428dec6b.zip
Revert "Merge pull request #8313 from alan/only_save_changed_has_one_objects"
This reverts commit 6e3ab3e15faf782f6a937ccf5574a4fb63e3e353, reversing changes made to 39e07b64ce3f4bb55e60ba0266e677f8e4f4893a. Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/autosave_association_test.rb
Diffstat (limited to 'activerecord/lib/active_record/autosave_association.rb')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index 213b72b933..e9622ca0c1 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -377,16 +377,15 @@ 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
- elsif autosave != false
+ else
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