From 01162b3d77b50057791526d29b97c16a891b6048 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 18 Dec 2013 04:52:24 -0700 Subject: Fix nil assignment to polymorphic belongs_to Assigning nil to a polymorphic belongs_to would nullify its _id field by not its _type field. Fixes failing test from c141dfc838a5dca9f197814410fa5d44c143129c. Regression from 1678e959e973de32287b65c52ebc6cce87148951. --- .../active_record/associations/belongs_to_polymorphic_association.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb index 81d4abfa68..b710cf6bdb 100644 --- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb @@ -14,6 +14,11 @@ module ActiveRecord owner[reflection.foreign_type] = record.class.base_class.name end + def remove_keys + super + owner[reflection.foreign_type] = nil + end + def different_target?(record) super || record.class != klass end -- cgit v1.2.3