activerecord-jdbc-adapter
activerecord-jdbc-adapter copied to clipboard
[mssql] to_sql with limit not working
Hi,
I'm running a rails app with JRuby 9.0.5.0 Rails 4.2.5.1 MSSQL Server 2008
In activerecord-jdbc-adapter 1.3.19 and on master I get an error, when i use to_sql on a limit query.
User.where(id:[1,2]).limit(1).to_sql
NoMethodError: undefined method `map' for nil:NilClass
from /home/soeren/.rbenv/versions/jruby-9.0.5.0/lib/ruby/gems/shared/gems/arel-6.0.3/lib/arel/collectors/bind.rb:22:in `substitute_binds'
from /home/soeren/.rbenv/versions/jruby-9.0.5.0/lib/ruby/gems/shared/gems/activerecord-4.2.5.1/lib/active_record/relation.rb:552:in `to_sql'
from (irb):2:in `<eval>'
from org/jruby/RubyKernel.java:976:in `eval'
from org/jruby/RubyKernel.java:1287:in `loop'
from org/jruby/RubyKernel.java:1096:in `catch'
from org/jruby/RubyKernel.java:1096:in `catch'
from /home/soeren/.rbenv/versions/jruby-9.0.5.0/lib/ruby/gems/shared/gems/railties-4.2.5.1/lib/rails/commands/console.rb:110:in `start'
from /home/soeren/.rbenv/versions/jruby-9.0.5.0/lib/ruby/gems/shared/gems/railties-4.2.5.1/lib/rails/commands/console.rb:9:in `start'
from /home/soeren/.rbenv/versions/jruby-9.0.5.0/lib/ruby/gems/shared/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:68:in `console'
from /home/soeren/.rbenv/versions/jruby-9.0.5.0/lib/ruby/gems/shared/gems/railties-4.2.5.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /home/soeren/.rbenv/versions/jruby-9.0.5.0/lib/ruby/gems/shared/gems/railties-4.2.5.1/lib/rails/commands.rb:17:in `<top>'
from org/jruby/RubyKernel.java:937:in `require'
Its works correct without limit
User.where(id:[1,2]).to_sql
Any ideas?
I found that if I change
https://github.com/jruby/activerecord-jdbc-adapter/blob/e9366a5a25dc919e7fe7d6319410aec2e9532edb/lib/arel/visitors/sql_server/ng42.rb#L255
from
#def substitute_binds bvs; @delegate.substitute_binds(bvs); self end
to
def substitute_binds bvs; @delegate.substitute_binds(bvs); end
...it fixes the problem. I must say I don't really understand it though :smirk: