Several “having” articles explode Rails 3 / Arel

I think I found a bug in Rails 3 / Arel, but I hope someone can clarify my problem before I try to fix it and / or send a bug report.

  • In a very simple application with the Question: model (submitter_id: integer, option_count: integer)

The code I'm using is:

q = Question.where(:submitter_id => 1) q = q.having(['option_sum > ?', 5]) q = q.having(['option_sum < ?', 10]) q = q.select("#{Question.table_name}.*, MAX(#{Question.table_name}.option_count) AS option_sum") q.to_sql q 

It explodes:

 ArgumentError: wrong number of arguments (2 for 1) from ~/.rvm/gems/ruby-1.9.2-p0/bundler/gems/arel-f092ae544f58/lib/arel/select_manager.rb:94:in `having' from ~/.rvm/gems/ruby-1.9.2-p0/bundler/gems/rails-76053fe4d12b/activerecord/lib/active_record/relation/query_methods.rb:193:in `build_arel' from ~/.rvm/gems/ruby-1.9.2-p0/bundler/gems/rails-76053fe4d12b/activerecord/lib/active_record/relation/query_methods.rb:162:in `arel' 

The output of one of the “having” clauses fixes the problem and generates the correct SQL.

Any comments would be appreciated. Arel and Rails 3 are edge editions with the changes indicated in the error above.

+4
source share
2 answers

After extensive testing, this seems like a Rails error in the end, although I couldn’t confirm it. This problem also occurs in a minimal Rails Rails application.

+2
source

Sometimes Arel gives a similar error when the region operators are not in an order similar to SQL, for example, try calling select ("..") before the havings. Also, I'm not sure that multiple requests are allowed in such requests, so try q = q.having (['(option_sum>? AND option_sum <?)', 5, 10])

+2
source

All Articles