From 798465f13017c64e9fdf55b2f51bc9285f0cda49 Mon Sep 17 00:00:00 2001 From: Tys von Gaza Date: Thu, 7 Apr 2011 10:44:17 -0600 Subject: [PATCH] updating patch for v2.3.11 --- .../belongs_to_polymorphic_association.rb | 2 +- .../associations/belongs_to_associations_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 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 f6edd63..b315223 100644 --- a/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb +++ b/activerecord/lib/active_record/associations/belongs_to_polymorphic_association.rb @@ -8,7 +8,7 @@ module ActiveRecord @target = (AssociationProxy === record ? record.target : record) @owner[@reflection.primary_key_name] = record_id(record) - @owner[@reflection.options[:foreign_type]] = record.class.base_class.name.to_s + @owner[@reflection.options[:foreign_type]] = record.class.name.to_s @updated = true end diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index ab0edee..537055d 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -372,6 +372,20 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal "Member", sponsor.sponsorable_type end + def test_polymorphic_assignment_foreign_type_field_updating_with_single_table_inheritence + # should update when assigning a saved record + sponsor = Sponsor.new + member = SpecialClient.create + sponsor.sponsorable = member + assert_equal "SpecialClient", sponsor.sponsorable_type + + # should update when assigning a new record + sponsor = Sponsor.new + member = VerySpecialClient.new + sponsor.sponsorable = member + assert_equal "VerySpecialClient", sponsor.sponsorable_type + end + def test_polymorphic_assignment_with_primary_key_foreign_type_field_updating # should update when assigning a saved record essay = Essay.new -- 1.7.4.2