Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Problem with .and()? - private method `format' called for #<Arel::Predicates::Equality:0x142d80c>

#5490

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

Reported by James Harton · August 30th, 2010 @ 02:17 AM

State: committed
Milestone: none
Assigned to: Aaron Patterson Aaron Patterson
Importance: Low

Activity

  1. James Harton
    James Harton
    • Title changed from private method `format' called for #<Arel::Predicates::Equality:0x142d80c> to Problem with .and()? - private method `format' called for #<Arel::Predicates::Equality:0x142d80c>
    • Assigned user set to Aaron Patterson

    September 1st, 2010 @ 10:53 PM

  2. Neeraj Singh
    Neeraj Singh
    • State changed from new to open
    • Tag changed from arel rails3 to arel rails3, patch
    • Importance changed from to Low

    Attached is patch for Arel with test.

    September 8th, 2010 @ 11:17 AM

  3. Aaron Patterson
    Aaron Patterson
    • State changed from open to committed

    Thanks Neeraj! I've applied the patch!

    September 8th, 2010 @ 04:26 PM