diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-11-17 14:52:38 -0800 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-11-17 14:52:38 -0800 |
commit | 590c784a30b13153667f8db7915998d7731e24e5 (patch) | |
tree | 4ac5e5ed038cb6c57c453909b344231603ee2928 /lib/arel/collectors | |
parent | 5035526b534a5d7c9d95eb6b66ade349c3a947f0 (diff) | |
download | rails-590c784a30b13153667f8db7915998d7731e24e5.tar.gz rails-590c784a30b13153667f8db7915998d7731e24e5.tar.bz2 rails-590c784a30b13153667f8db7915998d7731e24e5.zip |
Add order to BindParams in the ToSql collector
This removes the need for us to do the re-ordering by walking the AST in
ActiveRecord. We're using a block to communicate with the collector,
since the collector needs to be the thing which knows about the index,
while the visitor is the thing that needs to know the syntax. The
BindParam needs to know about neither of these things, so it's been
changed to stop being a subclass of SqlLiteral
I could also see an alternative implementation using format strings if
for some reason blocks cause a problem.
Diffstat (limited to 'lib/arel/collectors')
-rw-r--r-- | lib/arel/collectors/sql_string.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/arel/collectors/sql_string.rb b/lib/arel/collectors/sql_string.rb index 8ca89ca7bd..fd2faaef3a 100644 --- a/lib/arel/collectors/sql_string.rb +++ b/lib/arel/collectors/sql_string.rb @@ -5,8 +5,14 @@ require 'arel/collectors/plain_string' module Arel module Collectors class SQLString < PlainString + def initialize(*) + super + @bind_index = 1 + end + def add_bind bind - self << bind.to_s + self << yield(@bind_index) + @bind_index += 1 self end |