aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/autosave_association.rb
diff options
context:
space:
mode:
authorAlan Kennedy <alankennedy100@gmail.com>2014-09-15 09:18:24 +0100
committerAlan Kennedy <alankennedy100@gmail.com>2014-09-15 15:34:39 +0100
commit93717f39b7a59569b3ae5ed09d1cf782aec764f2 (patch)
treef2e4f93959b77f5b001046c5413f48d6865bb25c /activerecord/lib/active_record/autosave_association.rb
parent62955c77bf380fe39005c1a7de8b8fde769af2cd (diff)
downloadrails-93717f39b7a59569b3ae5ed09d1cf782aec764f2.tar.gz
rails-93717f39b7a59569b3ae5ed09d1cf782aec764f2.tar.bz2
rails-93717f39b7a59569b3ae5ed09d1cf782aec764f2.zip
Don't autosave unchanged has_one through records
Diffstat (limited to 'activerecord/lib/active_record/autosave_association.rb')
-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.