The following Arel code is throwing an error since Rails 3.0.0
stable was released (it was working on 3.0.0.rc2):
[Development]>> ct = Connection.arel_table
=> #<Arel::Table:0x15cb150 @name="connections", @table_exists=nil, @table_alias=nil, @christener=#<Arel::Sql::Christener:0x15cb13c @names={}>, @attributes=nil, @matching_attributes=nil, @engine=#<Arel::Sql::Engine:0xac01d4 @ar=ActiveRecord::Base, @adapter_name="PostgreSQL">>
[Development]>> clusters = ct.where(ct[:type].eq('Follow').and(ct[:user_id].eq(2))).to_sql
NoMethodError: private method `format' called for #<Arel::Predicates::Equality:0x3064084>
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/algebra/predicates.rb:142:in `to_sql'
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/algebra/relations/relation.rb:86:in `block in where_clauses'
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/algebra/relations/relation.rb:86:in `map'
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/algebra/relations/relation.rb:86:in `where_clauses'
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/engines/sql/relations/compiler.rb:35:in `build_clauses'
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/engines/sql/relations/compiler.rb:27:in `select_sql'
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/engines/sql/compilers/postgresql_compiler.rb:30:in `select_sql'
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/arel-1.0.1/lib/arel/algebra/relations/operations/where.rb:21:in `to_sql'
from (irb):7
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/commands/console.rb:44:in `start'
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/commands/console.rb:8:in `start'
from /Users/jnh/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.0/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:9:in `require'
from script/rails:9:in `<main>'
Interestingly, neither predicate fails on it's own:
[Development]>> clusters = ct.where(ct[:type].eq('Follow')).to_sql
=> "SELECT \"connections\".\"id\", \"connections\".\"user_id\", \"connections\".\"cluster_id\", \"connections\".\"type\", \"connections\".\"created_at\", \"connections\".\"updated_at\" FROM \"connections\" WHERE \"connections\".\"type\" = 'Follow'"
[Development]>> clusters = ct.where(ct[:user_id].eq(2)).to_sql
=> "SELECT \"connections\".\"id\", \"connections\".\"user_id\", \"connections\".\"cluster_id\", \"connections\".\"type\", \"connections\".\"created_at\", \"connections\".\"updated_at\" FROM \"connections\" WHERE \"connections\".\"user_id\" = 2"
Thus I am fairly certain that the problem occurs within the
.and() predicate. Am I doing it wrong? I can't find a commit that
seems to change anything like this since 3.0.0.rc2