diff options
author | Denis Redozubov <denis.redozubov@gmail.com> | 2013-11-09 19:38:27 +0400 |
---|---|---|
committer | Denis Redozubov <denis.redozubov@gmail.com> | 2013-11-11 14:19:12 +0400 |
commit | 3ed5642e69b9a132c78bc0b1e54cbdc3753d8a94 (patch) | |
tree | eadd6e28bf48f2a3bbc58d59456f4048fe8f2033 /activerecord/lib/active_record | |
parent | 9d664b18df7a81b75e45bb99858f920de040e9fb (diff) | |
download | rails-3ed5642e69b9a132c78bc0b1e54cbdc3753d8a94.tar.gz rails-3ed5642e69b9a132c78bc0b1e54cbdc3753d8a94.tar.bz2 rails-3ed5642e69b9a132c78bc0b1e54cbdc3753d8a94.zip |
Fixes problem with replacing has_one association record with itself
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/has_one_association.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index 0008600418..944caacab6 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -26,11 +26,13 @@ module ActiveRecord load_target return self.target if !(target || record) - if (target != record) || record.changed? + + assigning_another_record = target != record + if assigning_another_record || record.changed? save &&= owner.persisted? transaction_if(save) do - remove_target!(options[:dependent]) if target && !target.destroyed? + remove_target!(options[:dependent]) if target && !target.destroyed? && assigning_another_record if record set_owner_attributes(record) |