aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJan Graichen <jgraichen@altimos.de>2017-09-19 23:48:17 +0200
committerJan Graichen <jgraichen@altimos.de>2017-09-19 23:55:44 +0200
commit024c6f35834ecae5dfee4bae4fb96396ad1520ef (patch)
tree21f93e3bdfc33ed0ef027bc219e457f16f812bdd /lib
parente760714a304e2fdc550e26b5073bb19204e39a93 (diff)
downloadrails-024c6f35834ecae5dfee4bae4fb96396ad1520ef.tar.gz
rails-024c6f35834ecae5dfee4bae4fb96396ad1520ef.tar.bz2
rails-024c6f35834ecae5dfee4bae4fb96396ad1520ef.zip
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/visitors/to_sql.rb3
1 files changed, 2 insertions, 1 deletions
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