From b172731f70dd1cd619348d910111451a4d70d09b Mon Sep 17 00:00:00 2001 From: Rhett Sutphin Date: Mon, 4 Jan 2010 16:56:12 -0600 Subject: [PATCH] removed branching based on storing full sti class when determining the type name with the encluded module, which causes issues with non-sti associations; Patch originally from Ryan Kinderman --- activerecord/lib/active_record/base.rb | 6 +----- activerecord/test/cases/reflection_test.rb | 12 ++++++++++++ activerecord/test/models/company_in_module.rb | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 026bf55..ba09472 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1558,11 +1558,7 @@ module ActiveRecord #:nodoc: # Nest the type name in the same module as this class. # Bar is "MyApp::Business::Bar" relative to MyApp::Business::Foo def type_name_with_module(type_name) - if store_full_sti_class - type_name - else - (/^::/ =~ type_name) ? type_name : "#{parent.name}::#{type_name}" - end + (/^::/ =~ type_name) ? type_name : "#{parent.name}::#{type_name}" end def default_select(qualified) diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb index 211cf1d..6b9163c 100644 --- a/activerecord/test/cases/reflection_test.rb +++ b/activerecord/test/cases/reflection_test.rb @@ -178,6 +178,18 @@ class ReflectionTest < ActiveRecord::TestCase ActiveRecord::Base.store_full_sti_class = true end + def test_association_reflection_with_store_full_sti_class_enabled + old = ActiveRecord::Base.store_full_sti_class + ActiveRecord::Base.store_full_sti_class = true + assert_reflection MyApplication::Business::Firm, + :clients_for_full_sti, + :klass => MyApplication::Business::Client, + :class_name => 'Client', + :table_name => 'companies' + ensure + ActiveRecord::Base.store_full_sti_class = old + end + def test_reflection_of_all_associations # FIXME these assertions bust a lot assert_equal 37, Firm.reflect_on_all_associations.size diff --git a/activerecord/test/models/company_in_module.rb b/activerecord/test/models/company_in_module.rb index cdda7a4..6e722ef 100644 --- a/activerecord/test/models/company_in_module.rb +++ b/activerecord/test/models/company_in_module.rb @@ -12,6 +12,7 @@ module MyApplication has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id" has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}' + has_many :clients_for_full_sti, :class_name => "Client" has_one :account, :class_name => 'MyApplication::Billing::Account', :dependent => :destroy end -- 1.6.1