diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index 241b9bf..bfd511a 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -178,7 +178,7 @@ module ActiveRecord def set_belongs_to_association_for(record) if @reflection.options[:as] record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record? - record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.name.to_s + record["#{@reflection.options[:as]}_type"] = @owner.class.name.to_s else unless @owner.new_record? primary_key = @reflection.options[:primary_key] || :id diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 21412d1..02152e4 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -143,16 +143,28 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase def test_set_polymorphic_has_many tagging = tags(:misc).taggings.create - posts(:thinking).taggings << tagging + posts(:welcome).taggings << tagging assert_equal "Post", tagging.taggable_type end def test_set_polymorphic_has_one tagging = tags(:misc).taggings.create - posts(:thinking).tagging = tagging + posts(:welcome).tagging = tagging assert_equal "Post", tagging.taggable_type end - + + def test_set_polymorphic_has_many_with_sti_owner + tagging = tags(:misc).taggings.create + posts(:thinking).taggings << tagging + assert_equal "SpecialPost", tagging.taggable_type + end + + def test_set_polymorphic_has_one_with_sti_owner + tagging = tags(:misc).taggings.create + posts(:thinking).tagging = tagging + assert_equal "SpecialPost", tagging.taggable_type + end + def test_create_polymorphic_has_many_with_scope old_count = posts(:welcome).taggings.count tagging = posts(:welcome).taggings.create(:tag => tags(:misc))