From 2550acc779877720710cfaca120196109da70c04 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 10 Oct 2013 16:04:32 -0700 Subject: decouple the `join_constraints` method from the parent pointer --- activerecord/lib/active_record/associations/join_dependency.rb | 8 +++++++- .../associations/join_dependency/join_association.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 6e08f67286..ead2668250 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -80,7 +80,7 @@ module ActiveRecord end def join_constraints - join_root.children.flat_map { |c| c.flat_map(&:join_constraints) } + make_joins join_root end def columns @@ -111,6 +111,12 @@ module ActiveRecord private + def make_joins(node) + node.children.flat_map { |child| + child.join_constraints(node).concat make_joins(child) + } + end + def merge_node(left, right) intersection, missing = right.children.map { |node1| [left.children.find { |node2| node1.match? node2 }, node1] diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index 3af613d2d1..0d3834240c 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -38,7 +38,7 @@ module ActiveRecord super && reflection == other.reflection end - def join_constraints + def join_constraints(parent) joins = [] tables = @tables.dup -- cgit v1.2.3