Exists? weirdness

This works:

@items = Item.find( :all, :conditions => [ “category_id = ? AND
position = ?”, category_id, position ] )
if @items.size > 0 …

But this:

if Item.exists?( :conditions => [ “category_id = ? AND position = ?”,
category_id, position ] )…

Gives this error despite the documentation for Active Record Query
Interface which says
“Further more, exists takes a conditions option much like find:”…

SQLite3::SQLException: no such column: items.conditions: SELECT
“items”.id FROM “items” WHERE (“items”.“conditions” IN (‘category_id
= ? AND position = ?’,4,3.0)) LIMIT 1

Any idea why?

Many TIA,
Craig

On Sep 25, 2009, at 7:05 PM, Dudebot wrote:

This works:

@items = Item.find( :all, :conditions => [ “category_id = ? AND
position = ?”, category_id, position ] )
if @items.size > 0 …

But this:

if Item.exists?( :conditions => [ “category_id = ? AND position = ?”,
category_id, position ] )…

Try it like:
Item.exists?([“category_id = ? AND position = ?”, category_id,
position])
Or:
Item.exists?(:category_id => category_id, :position => position)

It wants the value of the conditions key in the options hash.

-Rob

Many TIA,
Craig

Rob B. http://agileconsultingllc.com
[email protected]