From 93717f39b7a59569b3ae5ed09d1cf782aec764f2 Mon Sep 17 00:00:00 2001 From: Alan Kennedy Date: Mon, 15 Sep 2014 09:18:24 +0100 Subject: Don't autosave unchanged has_one through records --- activerecord/lib/active_record/autosave_association.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') 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 :autosave is enabled. -- cgit v1.2.3