diff options
author | Matthew Draper <matthew@trebex.net> | 2017-05-24 13:15:21 +0930 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-24 13:15:21 +0930 |
commit | 28ed6a4f557ae50cdddf89c2606e76d239fc77c2 (patch) | |
tree | c0dcaccfeefe201d240eee5543db65430f6b89ae /activerecord/lib/active_record | |
parent | 3a354792a2498e60a7d9934e30b8840ad1719ff6 (diff) | |
parent | 54a030fb9ad705a0c2cfcb9e839eea0d1923b6ac (diff) | |
download | rails-28ed6a4f557ae50cdddf89c2606e76d239fc77c2.tar.gz rails-28ed6a4f557ae50cdddf89c2606e76d239fc77c2.tar.bz2 rails-28ed6a4f557ae50cdddf89c2606e76d239fc77c2.zip |
Merge pull request #29183 from kamipo/refactor_making_join_constraints
Refactor making join constraints
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 29 |
1 files changed, 6 insertions, 23 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 8995b1e352..643226267c 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -106,12 +106,7 @@ module ActiveRecord def join_constraints(outer_joins, join_type) joins = join_root.children.flat_map { |child| - - if join_type == Arel::Nodes::OuterJoin - make_left_outer_joins join_root, child - else - make_inner_joins join_root, child - end + make_join_constraints(join_root, child, join_type) } joins.concat outer_joins.flat_map { |oj| @@ -175,27 +170,15 @@ module ActiveRecord end def make_outer_joins(parent, child) - tables = table_aliases_for(parent, child) - join_type = Arel::Nodes::OuterJoin - info = make_constraints parent, child, tables, join_type - - [info] + child.children.flat_map { |c| make_outer_joins(child, c) } - end - - def make_left_outer_joins(parent, child) - tables = child.tables join_type = Arel::Nodes::OuterJoin - info = make_constraints parent, child, tables, join_type - - [info] + child.children.flat_map { |c| make_left_outer_joins(child, c) } + make_join_constraints(parent, child, join_type, true) end - def make_inner_joins(parent, child) - tables = child.tables - join_type = Arel::Nodes::InnerJoin - info = make_constraints parent, child, tables, join_type + def make_join_constraints(parent, child, join_type, aliasing = false) + tables = aliasing ? table_aliases_for(parent, child) : child.tables + info = make_constraints(parent, child, tables, join_type) - [info] + child.children.flat_map { |c| make_inner_joins(child, c) } + [info] + child.children.flat_map { |c| make_join_constraints(child, c, join_type, aliasing) } end def table_aliases_for(parent, node) |