aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/base.rb12
-rw-r--r--activerecord/lib/active_record/reflection.rb5
2 files changed, 9 insertions, 8 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
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