diff options
author | Alan Kennedy <alankennedy100@gmail.com> | 2014-09-15 09:18:24 +0100 |
---|---|---|
committer | Alan Kennedy <alankennedy100@gmail.com> | 2014-09-15 15:34:39 +0100 |
commit | 93717f39b7a59569b3ae5ed09d1cf782aec764f2 (patch) | |
tree | f2e4f93959b77f5b001046c5413f48d6865bb25c /activerecord/lib | |
parent | 62955c77bf380fe39005c1a7de8b8fde769af2cd (diff) | |
download | rails-93717f39b7a59569b3ae5ed09d1cf782aec764f2.tar.gz rails-93717f39b7a59569b3ae5ed09d1cf782aec764f2.tar.bz2 rails-93717f39b7a59569b3ae5ed09d1cf782aec764f2.zip |
Don't autosave unchanged has_one through records
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 4 |
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. |