This project is archived and is in readonly mode.
Hash conditions fail with PostgreSQL ENUMs
Reported by JackC | November 30th, 2010 @ 05:22 PM
Cannot query a table by an enumerated field.
For example, when gender is a PostgreSQL enum:
irb(main):004:0> Person.where(:gender => "male").first
NoMethodError: undefined method `visit_Arel_Attributes_Undefined' for #<Arel::Visitors::PostgreSQL:0x7f0c52d6b310>
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/visitor.rb:15:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/visitor.rb:15:in `visit'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:235:in `visit_Arel_Nodes_Equality'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/visitor.rb:15:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/visitor.rb:15:in `visit'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:109:in `visit_Arel_Nodes_Grouping'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/visitor.rb:15:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/visitor.rb:15:in `visit'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:89:in `visit_Arel_Nodes_SelectCore'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:89:in `map'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:89:in `visit_Arel_Nodes_SelectCore'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:77:in `visit_Arel_Nodes_SelectStatement'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:77:in `map'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:77:in `visit_Arel_Nodes_SelectStatement'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/postgresql.rb:24:in `visit_Arel_Nodes_SelectStatement'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/visitor.rb:15:in `send'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/visitor.rb:15:in `visit'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/visitor.rb:5:in `accept'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:19:in `accept'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/connection_adapters/abstract/connection_pool.rb:110:in `with_connection'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/visitors/to_sql.rb:17:in `accept'
from /usr/local/lib/ruby/gems/1.8/gems/arel-2.0.4/lib/arel/tree_manager.rb:19:in `to_sql'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation.rb:64:in `to_a'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:333:in `find_first'
from /usr/local/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/relation/finder_methods.rb:122:in `first'
from (irb):4
Querying via array substitution works:
Person.where(["gender=?", "male"]).first
This used to work in Rails 3.0.1.
Comments and changes to this ticket
-
Neeraj Singh December 1st, 2010 @ 05:14 AM
- Importance changed from to Low
In edge rails both of these work.
ree-1.8.7-2010.02 > Car.where(:name => 'honda').first Car Load (0.2ms) SELECT "cars".* FROM "cars" WHERE "cars"."name" = 'honda' LIMIT 1 => #<Car id: 1, name: "honda", color: nil> ree-1.8.7-2010.02 > Car.where(["name = ?",'honda']).first Car Load (0.2ms) SELECT "cars".* FROM "cars" WHERE (name = 'honda') LIMIT 1 => #<Car id: 1, name: "honda", color: nil> ree-1.8.7-2010.02 >
-
Tom Hughes February 9th, 2011 @ 10:57 PM
Well rails 3.0.4 is out now, but this still seems to be failing?
-
Tom Hughes February 10th, 2011 @ 12:39 AM
It seems the answer is to update arel - rails 3.0.4 was still only requiring arel 2.0.2 or later and I had 2.0.3 which was sufficient for that. Updating arel to 2.0.8 seems to fix the problem.
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>