aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/join_dependency.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-10-15 15:39:11 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-10-15 15:39:11 -0700
commitc5fe508df19028d9fcb5c958019f61b55b24edb1 (patch)
tree67a13815062c537dc7fbdf56098ded4c0f8d1dcd /activerecord/lib/active_record/associations/join_dependency.rb
parentc746b5339087825b1fe79abc426170baf1b51e5c (diff)
downloadrails-c5fe508df19028d9fcb5c958019f61b55b24edb1.tar.gz
rails-c5fe508df19028d9fcb5c958019f61b55b24edb1.tar.bz2
rails-c5fe508df19028d9fcb5c958019f61b55b24edb1.zip
apply tables to the whole tree from the outside
Diffstat (limited to 'activerecord/lib/active_record/associations/join_dependency.rb')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb22
1 files changed, 8 insertions, 14 deletions
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