diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-21 14:53:33 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-21 14:53:33 -0700 |
commit | aa5affbff3e89efcefa728cb127c5d8eed993370 (patch) | |
tree | db297023069d5667e1fba9c6fe1daeeb079afad1 | |
parent | 00a426ee373e32132729c825ac266b21032c1cfd (diff) | |
download | rails-aa5affbff3e89efcefa728cb127c5d8eed993370.tar.gz rails-aa5affbff3e89efcefa728cb127c5d8eed993370.tar.bz2 rails-aa5affbff3e89efcefa728cb127c5d8eed993370.zip |
make joins generation method look similar
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index dab8b75b5c..fb893da0da 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -66,7 +66,9 @@ module ActiveRecord end def join_constraints(outer_joins) - joins = make_inner_joins join_root + joins = join_root.children.flat_map { |child| + make_inner_joins join_root, child + } joins.concat outer_joins.flat_map { |oj| if join_root.match? oj.join_root @@ -169,11 +171,12 @@ module ActiveRecord joins.concat child.children.flat_map { |c| make_outer_joins(child, c) } end - def make_inner_joins(parent) - parent.children.flat_map { |child| - joins = make_constraints(parent, child, child.tables, Arel::InnerJoin) - joins.concat make_inner_joins(child) - } + def make_inner_joins(parent, child) + tables = child.tables + join_type = Arel::InnerJoin + joins = make_constraints parent, child, tables, join_type + + joins.concat child.children.flat_map { |c| make_inner_joins(child, c) } end def table_aliases_for(parent, node) |