aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2013-12-18 04:52:24 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2013-12-18 04:52:24 -0700
commit01162b3d77b50057791526d29b97c16a891b6048 (patch)
tree96fe687ec673222d94c6a11bc463e5e3f6519d78 /activerecord
parent06dc51a6c07b79c069fc975622c50ac7181ae845 (diff)
downloadrails-01162b3d77b50057791526d29b97c16a891b6048.tar.gz
rails-01162b3d77b50057791526d29b97c16a891b6048.tar.bz2
rails-01162b3d77b50057791526d29b97c16a891b6048.zip
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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb5
1 files changed, 5 insertions, 0 deletions
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