aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-06-30 11:24:39 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-06-30 15:31:22 -0700
commitf261ef42cc2c8f0fc31d6e6f464bacd6ca9eb581 (patch)
treeac1d59aaac3d0dc0d9fc5d42fbcf092aa009f6d9 /activerecord/lib/active_record/reflection.rb
parent2ebc564394c5aec3d135e774dece6127147ba0c5 (diff)
downloadrails-f261ef42cc2c8f0fc31d6e6f464bacd6ca9eb581.tar.gz
rails-f261ef42cc2c8f0fc31d6e6f464bacd6ca9eb581.tar.bz2
rails-f261ef42cc2c8f0fc31d6e6f464bacd6ca9eb581.zip
cache the plural name on the reflection so we do not pay pluralize costs on joins
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r--activerecord/lib/active_record/reflection.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 6df473d011..57023f5388 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -80,12 +80,6 @@ module ActiveRecord
# 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 @@ module ActiveRecord
# <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