Skip to content
Browse files

apply table aliases after the AST has been built

  • Loading branch information...
1 parent db2e21a commit c746b5339087825b1fe79abc426170baf1b51e5c @tenderlove tenderlove committed Oct 15, 2013
Showing with 13 additions and 1 deletion.
  1. +13 −1 activerecord/lib/active_record/associations/join_dependency.rb
View
14 activerecord/lib/active_record/associations/join_dependency.rb
@@ -58,6 +58,9 @@ def initialize(base, associations, joins)
@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 @@ def merge_outer_joins!(other)
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 @@ def make_joins(node)
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 @@ def build_join_association(reflection, parent, join_type)
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

0 comments on commit c746b53

Please sign in to comment.
Something went wrong with that request. Please try again.