aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-02-22 18:44:14 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-02-22 18:44:14 +0000
commitc7d6d68f91f2cd2e04c2113cba44bef86dbad99f (patch)
treef9c4a03d7254d648718e671c4619f8637235b428 /activerecord/lib/active_record/base.rb
parentde54db3c1e2056322450e46c265b27792e99b2c7 (diff)
downloadrails-c7d6d68f91f2cd2e04c2113cba44bef86dbad99f.tar.gz
rails-c7d6d68f91f2cd2e04c2113cba44bef86dbad99f.tar.bz2
rails-c7d6d68f91f2cd2e04c2113cba44bef86dbad99f.zip
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
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb12
1 files changed, 7 insertions, 5 deletions
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