diff options
author | Jan Graichen <jgraichen@altimos.de> | 2017-09-19 23:48:17 +0200 |
---|---|---|
committer | Jan Graichen <jgraichen@altimos.de> | 2017-09-19 23:55:44 +0200 |
commit | 024c6f35834ecae5dfee4bae4fb96396ad1520ef (patch) | |
tree | 21f93e3bdfc33ed0ef027bc219e457f16f812bdd /lib | |
parent | e760714a304e2fdc550e26b5073bb19204e39a93 (diff) | |
download | rails-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.rb | 3 |
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 |