This project is archived and is in readonly mode.

#5490 ✓committed
James Harton

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

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

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

Comments and changes to this ticket

  • James Harton

    James Harton September 1st, 2010 @ 10:53 PM

    • 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”
  • Neeraj Singh

    Neeraj Singh September 8th, 2010 @ 11:17 AM

    • 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.

  • Aaron Patterson

    Aaron Patterson September 8th, 2010 @ 04:26 PM

    • State changed from “open” to “committed”

    Thanks Neeraj! I've applied the patch!

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages