From c7d6d68f91f2cd2e04c2113cba44bef86dbad99f Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 22 Feb 2006 18:44:14 +0000 Subject: Reflections don't attempt to resolve module nesting of association classes. Simplify type computation. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3637 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/base.rb | 12 +++++++----- activerecord/lib/active_record/reflection.rb | 5 ++--- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index e040c86505..681f99b5c0 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -956,10 +956,10 @@ module ActiveRecord #:nodoc: object end - # Returns the name of the type of the record using the current module as a prefix. So descendents of - # MyApp::Business::Account would appear as "MyApp::Business::AccountSubclass". + # 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) - self.name =~ /::/ ? self.name.scan(/(.*)::/).first.first + "::" + type_name : type_name + "#{self.name.sub(/(::)?[^:]+$/, '')}#{$1}#{type_name}" end def construct_finder_sql(options) @@ -1152,8 +1152,10 @@ module ActiveRecord #:nodoc: # Returns the class type of the record using the current module as a prefix. So descendents of # MyApp::Business::Account would appear as MyApp::Business::AccountSubclass. def compute_type(type_name) - type_name_with_module(type_name).split("::").inject(Object) do |final_type, part| - final_type.const_get(part) + begin + instance_eval(type_name_with_module(type_name)) + rescue Object + instance_eval(type_name) end end diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 9bac82f5ce..2f73300abf 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -136,13 +136,12 @@ module ActiveRecord name else if options[:class_name] - class_name = options[:class_name] + options[:class_name] else class_name = name.to_s.camelize class_name = class_name.singularize if [ :has_many, :has_and_belongs_to_many ].include?(macro) + class_name end - - active_record.send(:type_name_with_module, class_name) end end end -- cgit v1.2.3