From 024c6f35834ecae5dfee4bae4fb96396ad1520ef Mon Sep 17 00:00:00 2001 From: Jan Graichen Date: Tue, 19 Sep 2017 23:48:17 +0200 Subject: 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. --- lib/arel/visitors/to_sql.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 3ed80c8f06..6aaaa19e6e 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -427,7 +427,8 @@ module Arel end def visit_Arel_SelectManager o, collector - collector << "(#{o.to_sql.rstrip})" + collector << '(' + visit(o.ast, collector) << ')' end def visit_Arel_Nodes_Ascending o, collector -- cgit v1.2.3