diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-21 14:28:35 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-21 14:28:35 -0700 |
commit | 0480b8c717c3a76c8d7fa30236d5a843c8a675b2 (patch) | |
tree | 90c65d33b411167e548a1225c215c809ad141ea5 /activerecord | |
parent | 7894ae39c8313d83d64d5a058470ec1ef4ed22e1 (diff) | |
download | rails-0480b8c717c3a76c8d7fa30236d5a843c8a675b2.tar.gz rails-0480b8c717c3a76c8d7fa30236d5a843c8a675b2.tar.bz2 rails-0480b8c717c3a76c8d7fa30236d5a843c8a675b2.zip |
add outer joins for matching nodes
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb index 711b15be4a..1ffa4a0a6b 100644 --- a/activerecord/lib/active_record/associations/join_dependency.rb +++ b/activerecord/lib/active_record/associations/join_dependency.rb @@ -89,8 +89,8 @@ module ActiveRecord 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 @@ module ActiveRecord 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] |