提交 f261ef42 编写于 作者: A Aaron Patterson

cache the plural name on the reflection so we do not pay pluralize costs on joins

上级 2ebc5643
......@@ -32,7 +32,7 @@ def table_name_for(reflection)
end
def table_alias_for(reflection, join = false)
name = alias_tracker.pluralize(reflection.name, reflection.active_record)
name = reflection.plural_name.dup
name << "_#{alias_suffix}"
name << "_join" if join
name
......
......@@ -80,12 +80,6 @@ def reflect_on_all_autosave_associations
# Abstract base class for AggregateReflection and AssociationReflection. Objects of
# AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.
class MacroReflection
attr_reader :active_record
def initialize(macro, name, options, active_record)
@macro, @name, @options, @active_record = macro, name, options, active_record
end
# Returns the name of the macro.
#
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns <tt>:balance</tt>
......@@ -104,6 +98,19 @@ def initialize(macro, name, options, active_record)
# <tt>has_many :clients</tt> returns +{}+
attr_reader :options
attr_reader :active_record
attr_reader :plural_name # :nodoc:
def initialize(macro, name, options, active_record)
@macro = macro
@name = name
@options = options
@active_record = active_record
@plural_name = active_record.pluralize_table_names ?
name.to_s.pluralize : name.to_s
end
# Returns the class for the macro.
#
# <tt>composed_of :balance, :class_name => 'Money'</tt> returns the Money class
......
......@@ -76,7 +76,7 @@ def test_integer_columns
end
def test_reflection_klass_for_nested_class_name
reflection = MacroReflection.new(nil, nil, { :class_name => 'MyApplication::Business::Company' }, nil)
reflection = MacroReflection.new(:company, nil, { :class_name => 'MyApplication::Business::Company' }, ActiveRecord::Base)
assert_nothing_raised do
assert_equal MyApplication::Business::Company, reflection.klass
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册