From c5fe508df19028d9fcb5c958019f61b55b24edb1 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 15 Oct 2013 15:39:11 -0700 Subject: apply tables to the whole tree from the outside --- .../active_record/associations/join_dependency.rb | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index f16013ff6a..ce1c5e2c5e 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -58,9 +58,7 @@ module ActiveRecord @alias_tracker.aliased_name_for(base.table_name) # Updates the count for base.table_name to 1 tree = self.class.make_tree associations build tree, @join_root, Arel::InnerJoin - @join_root.children.each do |child| - apply_tables! @join_root, child - end + apply_tables! @join_root end def reflections @@ -79,9 +77,11 @@ module ActiveRecord deep_copy left, node } end - @join_root.children.each do |child| - apply_tables! @join_root, child - end + apply_tables! @join_root + end + + def apply_tables!(node) + node.children.each { |child| construct_tables! node, child } end def join_constraints @@ -171,14 +171,13 @@ module ActiveRecord end def construct_tables!(parent, node) - return if node.tables - node.tables = node.reflection.chain.map { |reflection| alias_tracker.aliased_table_for( reflection.table_name, table_alias_for(reflection, parent, reflection != node.reflection) ) - } + } unless node.tables + node.children.each { |child| construct_tables! node, child } end def table_alias_for(reflection, parent, join) @@ -228,11 +227,6 @@ module ActiveRecord node end - def apply_tables!(parent, node) - construct_tables!(parent, node) - node.children.each { |child| apply_tables! node, child } - end - def construct(ar_parent, parent, row, rs, seen, model_cache, aliases) primary_id = ar_parent.id -- cgit v1.2.3