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.
source share