aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-09-17 16:26:35 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-09-17 16:26:35 -0300
commitafa47805720bd7f315536fc08d5360a514cb2422 (patch)
tree74d29f6110cd50c2e200e28b0d014733a99320c4 /activerecord/lib/active_record
parent3fd016b2dc9950670c33fa6a5d31bb215f705a50 (diff)
parent93717f39b7a59569b3ae5ed09d1cf782aec764f2 (diff)
downloadrails-afa47805720bd7f315536fc08d5360a514cb2422.tar.gz
rails-afa47805720bd7f315536fc08d5360a514cb2422.tar.bz2
rails-afa47805720bd7f315536fc08d5360a514cb2422.zip
Merge pull request #16875 from alan/dont_autosave_has_one_through_record
Don't autosave unchanged has_one through records Conflicts: activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/autosave_association.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb
index a8e4d25df2..2a5dd758a3 100644
--- a/activerecord/lib/active_record/autosave_association.rb
+++ b/activerecord/lib/active_record/autosave_association.rb
@@ -403,7 +403,9 @@ module ActiveRecord
# If the record is new or it has changed, returns true.
def record_changed?(reflection, record, key)
- record.new_record? || record[reflection.foreign_key] != key || record.attribute_changed?(reflection.foreign_key)
+ record.new_record? ||
+ (record.attributes.keys.include?(reflection.foreign_key) && record[reflection.foreign_key] != key) ||
+ record.attribute_changed?(reflection.foreign_key)
end
# Saves the associated record if it's new or <tt>:autosave</tt> is enabled.