Permalink
Browse files

apply tables to the whole tree from the outside

  • Loading branch information...
tenderlove committed Oct 15, 2013
1 parent c746b53 commit c5fe508df19028d9fcb5c958019f61b55b24edb1
Showing with 8 additions and 14 deletions.
  1. +8 −14 activerecord/lib/active_record/associations/join_dependency.rb
@@ -58,9 +58,7 @@ 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
+ apply_tables! @join_root
end
def reflections
@@ -79,9 +77,11 @@ def merge_outer_joins!(other)
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 @@ 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,
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 @@ def build_join_association(reflection, parent, join_type)
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 c5fe508

Please sign in to comment.