From c746b5339087825b1fe79abc426170baf1b51e5c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 15 Oct 2013 15:34:59 -0700 Subject: apply table aliases after the AST has been built --- .../lib/active_record/associations/join_dependency.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 66cc5bd3ac..f16013ff6a 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -58,6 +58,9 @@ 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 end def reflections @@ -76,6 +79,9 @@ module ActiveRecord deep_copy left, node } end + @join_root.children.each do |child| + apply_tables! @join_root, child + end end def join_constraints @@ -165,6 +171,8 @@ 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, @@ -217,10 +225,14 @@ module ActiveRecord end node = JoinAssociation.new(reflection, join_type) - construct_tables!(parent, node) 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