Permalink
Browse files

bubble bind parameters up when building join dependencies

  • Loading branch information...
1 parent c4e9dc2 commit 3086881001ed0007eee76f23cf54a7dda88bf792 @tenderlove tenderlove committed Jan 13, 2014
@@ -164,17 +164,17 @@ def make_constraints(parent, child, tables, join_type)
def make_outer_joins(parent, child)
tables = table_aliases_for(parent, child)
join_type = Arel::OuterJoin
- joins = make_constraints parent, child, tables, join_type
+ info = make_constraints parent, child, tables, join_type
- joins.concat child.children.flat_map { |c| make_outer_joins(child, c) }
+ [info] + child.children.flat_map { |c| make_outer_joins(child, c) }
end
def make_inner_joins(parent, child)
tables = child.tables
join_type = Arel::InnerJoin
- joins = make_constraints parent, child, tables, join_type
+ info = make_constraints parent, child, tables, join_type
- joins.concat child.children.flat_map { |c| make_inner_joins(child, c) }
+ [info] + child.children.flat_map { |c| make_inner_joins(child, c) }
end
def table_aliases_for(parent, node)
@@ -21,8 +21,11 @@ def match?(other)
super && reflection == other.reflection
end
+ JoinInformation = Struct.new :joins, :binds
+
def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scope_chain, chain)
joins = []
+ bind_values = []
tables = tables.reverse
scope_chain_iter = scope_chain.reverse_each
@@ -64,8 +67,12 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop
left.merge right
end
- if rel && !rel.arel.constraints.empty?
- constraint = constraint.and rel.arel.constraints
+ if rel
+ bind_values.concat rel.bind_values
+
+ if !rel.arel.constraints.empty?
+ constraint = constraint.and rel.arel.constraints
+ end
end
joins << table.create_join(table, table.create_on(constraint), join_type)
@@ -74,7 +81,7 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop
foreign_table, foreign_klass = table, klass
end
- joins
+ JoinInformation.new joins, bind_values
end
# Builds equality condition.
@@ -1006,9 +1006,12 @@ def build_joins(manager, joins)
join_list
)
- joins = join_dependency.join_constraints stashed_association_joins
+ join_infos = join_dependency.join_constraints stashed_association_joins
- joins.each { |join| manager.from(join) }
+ join_infos.each do |info|
+ info.joins.each { |join| manager.from(join) }
+ self.bind_values += info.binds
+ end
manager.join_sources.concat(join_list)

0 comments on commit 3086881

Please sign in to comment.