# Exists? weirdness

**URL:** <https://www.ruby-forum.com/t/exists-weirdness/176194>\
**Category:** Rails\
**Created:** [September 26, 2009, 1:07am UTC](https://www.ruby-forum.com/t/exists-weirdness/176194 "2009-09-26T01:07:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [September 26, 2009, 1:07am UTC](https://www.ruby-forum.com/t/exists-weirdness/176194/1 "2009-09-26T01:07:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [September 26, 2009, 1:53am UTC](https://www.ruby-forum.com/t/exists-weirdness/176194/2 "2009-09-26T01:53:47Z")

</div>

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](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
