aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/join_dependency.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/join_dependency.rb')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb14
1 files changed, 13 insertions, 1 deletions
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