Permalink
Browse files

add outer joins for matching nodes

  • Loading branch information...
1 parent 7894ae3 commit 0480b8c717c3a76c8d7fa30236d5a843c8a675b2 @tenderlove tenderlove committed Oct 21, 2013
Showing with 14 additions and 2 deletions.
  1. +14 −2 activerecord/lib/active_record/associations/join_dependency.rb
@@ -89,8 +89,8 @@ def join_constraints(outer_joins)
oj = outer_joins.first
if join_root.match? oj.join_root
- outer_joins.each { |oj| merge_outer_joins! oj }
- make_joins join_root
+ joins = make_joins join_root
+ joins + walk(join_root, oj.join_root)
else
make_joins(join_root) + outer_joins.flat_map { |join|
join.join_root.children.flat_map { |child|
@@ -219,6 +219,18 @@ def table_alias_for(reflection, parent, join)
name
end
+ def walk(left, right)
+ intersection, missing = right.children.map { |node1|
+ [left.children.find { |node2| node1.match? node2 }, node1]
+ }.partition(&:first)
+
+ ojs = missing.flat_map { |_,n|
+ make_the_joins left, n
+ }
+
+ intersection.flat_map { |l,r| walk l, r }.concat ojs
+ end
+
def merge_node(left, right)
intersection, missing = right.children.map { |node1|
[left.children.find { |node2| node1.match? node2 }, node1]

0 comments on commit 0480b8c

Please sign in to comment.