aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-07-16 13:35:37 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-07-16 13:35:37 -0700
commit743b67508e2027e1d086142ccbec47a19fc943f6 (patch)
tree12c2e7872ddbd52fd71d7fa9c211a116452cc4dd
parent560517689c3cf18736bcfe39c34985ddd001a2ca (diff)
downloadrails-743b67508e2027e1d086142ccbec47a19fc943f6.tar.gz
rails-743b67508e2027e1d086142ccbec47a19fc943f6.tar.bz2
rails-743b67508e2027e1d086142ccbec47a19fc943f6.zip
cache the klass member of the reflection
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb18
1 files changed, 10 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
index 75e4ed09a2..ee1fcc17d8 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -66,6 +66,7 @@ module ActiveRecord
def join_to(manager)
tables = @tables.dup
+
foreign_table = parent_table
foreign_klass = parent.base_klass
@@ -75,6 +76,7 @@ module ActiveRecord
# more sense in this context), so we reverse
chain.reverse_each do |reflection|
table = tables.shift
+ klass = reflection.klass
case reflection.source_macro
when :belongs_to
@@ -97,23 +99,23 @@ module ActiveRecord
foreign_key = reflection.active_record_primary_key
end
- constraint = build_constraint(reflection, table, key, foreign_table, foreign_key)
+ constraint = build_constraint(klass, table, key, foreign_table, foreign_key)
scope_chain_items = scope_chain_iter.next.map do |item|
if item.is_a?(Relation)
item
else
- ActiveRecord::Relation.new(reflection.klass, table).instance_exec(self, &item)
+ ActiveRecord::Relation.new(klass, table).instance_exec(self, &item)
end
end
if reflection.type
scope_chain_items <<
- ActiveRecord::Relation.new(reflection.klass, table)
+ ActiveRecord::Relation.new(klass, table)
.where(reflection.type => foreign_klass.base_class.name)
end
- scope_chain_items.concat [reflection.klass.send(:build_default_scope)].compact
+ scope_chain_items.concat [klass.send(:build_default_scope)].compact
rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right|
left.merge right
@@ -126,7 +128,7 @@ module ActiveRecord
manager.from(join(table, constraint))
# The current table in this iteration becomes the foreign table in the next
- foreign_table, foreign_klass = table, reflection.klass
+ foreign_table, foreign_klass = table, klass
end
manager
@@ -147,13 +149,13 @@ module ActiveRecord
# foreign_table #=> #<Arel::Table @name="physicians" ...>
# foreign_key #=> id
#
- def build_constraint(reflection, table, key, foreign_table, foreign_key)
+ def build_constraint(klass, table, key, foreign_table, foreign_key)
constraint = table[key].eq(foreign_table[foreign_key])
- if reflection.klass.finder_needs_type_condition?
+ if klass.finder_needs_type_condition?
constraint = table.create_and([
constraint,
- reflection.klass.send(:type_condition, table)
+ klass.send(:type_condition, table)
])
end