From 66556631f5b98990d55194f427533a4b992b3350 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 15 Oct 2013 15:11:52 -0700 Subject: pass the chain the join_constraints --- activerecord/lib/active_record/associations/join_dependency.rb | 3 ++- .../active_record/associations/join_dependency/join_association.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/associations') diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 7dffc3e3e5..68bdd41101 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -159,7 +159,8 @@ module ActiveRecord def make_joins(node) node.children.flat_map { |child| - child.join_constraints(node, child.tables).concat make_joins(child) + child.join_constraints(node, child.tables, child.reflection.chain) + .concat make_joins(child) } end 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 a6a7b447cc..b47ee17aff 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -25,7 +25,7 @@ module ActiveRecord super && reflection == other.reflection end - def join_constraints(parent, tables) + def join_constraints(parent, tables, chain) joins = [] tables = tables.dup @@ -36,7 +36,7 @@ module ActiveRecord # The chain starts with the target table, but we want to end with it here (makes # more sense in this context), so we reverse - reflection.chain.reverse_each do |reflection| + chain.reverse_each do |reflection| table = tables.shift klass = reflection.klass -- cgit v1.2.3