From d3fd9971093101712e4cc97ccc534631888b673d Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Sat, 15 Nov 2008 01:59:12 -0500 Subject: fix assignment to has_one :through associations. Signed-off-by: Michael Koziarski --- .../lib/active_record/associations/has_one_through_association.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/associations/has_one_through_association.rb') diff --git a/activerecord/lib/active_record/associations/has_one_through_association.rb b/activerecord/lib/active_record/associations/has_one_through_association.rb index b78bd5d931..8073ebaf9f 100644 --- a/activerecord/lib/active_record/associations/has_one_through_association.rb +++ b/activerecord/lib/active_record/associations/has_one_through_association.rb @@ -8,11 +8,10 @@ module ActiveRecord current_object = @owner.send(@reflection.through_reflection.name) if current_object - klass.destroy(current_object) - @owner.clear_association_cache + current_object.update_attributes(construct_join_attributes(new_value)) + else + @owner.send(@reflection.through_reflection.name, klass.send(:create, construct_join_attributes(new_value))) end - - @owner.send(@reflection.through_reflection.name, klass.send(:create, construct_join_attributes(new_value))) end private -- cgit v1.2.3