diff options
author | Jamis Buck <jamis@37signals.com> | 2005-10-13 19:21:45 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2005-10-13 19:21:45 +0000 |
commit | 99f3ae08450ecfd7574336837a75c7fd0dd17305 (patch) | |
tree | 772950a2a833e41301f1e410f7a2d1fc21b35ff6 /activerecord/lib/active_record | |
parent | 2f9a19cb834b5d44ccb28b87b979266820864dd1 (diff) | |
download | rails-99f3ae08450ecfd7574336837a75c7fd0dd17305.tar.gz rails-99f3ae08450ecfd7574336837a75c7fd0dd17305.tar.bz2 rails-99f3ae08450ecfd7574336837a75c7fd0dd17305.zip |
Fix errors caused by assigning a has-one or belongs-to property to itself
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2562 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/belongs_to_association.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/has_one_association.rb | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/belongs_to_association.rb b/activerecord/lib/active_record/associations/belongs_to_association.rb index 681bd1b88d..9dc0e26e10 100644 --- a/activerecord/lib/active_record/associations/belongs_to_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_association.rb @@ -30,7 +30,7 @@ module ActiveRecord else raise_on_type_mismatch(obj) unless obj.nil? - @target = obj + @target = (AssociationProxy === obj ? obj.target : obj) @owner[@association_class_primary_key_name] = obj.id unless obj.new_record? @updated = true end diff --git a/activerecord/lib/active_record/associations/has_one_association.rb b/activerecord/lib/active_record/associations/has_one_association.rb index 1550db69b5..1ff67ff70a 100644 --- a/activerecord/lib/active_record/associations/has_one_association.rb +++ b/activerecord/lib/active_record/associations/has_one_association.rb @@ -29,7 +29,7 @@ module ActiveRecord def replace(obj, dont_save = false) load_target unless @target.nil? - if dependent? && !dont_save + if dependent? && !dont_save && @target != obj @target.destroy unless @target.new_record? @owner.clear_association_cache else @@ -44,7 +44,7 @@ module ActiveRecord raise_on_type_mismatch(obj) obj[@association_class_primary_key_name] = @owner.id unless @owner.new_record? - @target = obj + @target = (AssociationProxy === obj ? obj.target : obj) end @loaded = true |