Skip to content

Commit 024c6f3

Browse files
committed
Support BindParams in subqueries
When an Arel AST contains a SelectManager as a component, e.g. as a CTE expression, the SelectManager is converted to SQL with `#to_sql`. This uses a new collector that leads to invalid expressions when using bind parameters. For example, when generating PostgreSQL queries, the bind parameter number starts from one again. When using the SubstituteBinds collector, binds in the subquery are not substituted. This commit changes the ToSql visitor to visit the SelectManager ast itself.
1 parent e760714 commit 024c6f3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/arel/visitors/to_sql.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ def visit_Arel_Nodes_Grouping o, collector
427427
end
428428

429429
def visit_Arel_SelectManager o, collector
430-
collector << "(#{o.to_sql.rstrip})"
430+
collector << '('
431+
visit(o.ast, collector) << ')'
431432
end
432433

433434
def visit_Arel_Nodes_Ascending o, collector

0 commit comments

Comments
 (0)