# Find(:conditions=\>cond\_selection

**URL:** <https://www.ruby-forum.com/t/find-conditions-cond-selection/171875>\
**Category:** Ruby\
**Created:** [July 10, 2009, 2:56pm UTC](https://www.ruby-forum.com/t/find-conditions-cond-selection/171875 "2009-07-10T14:56:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![softwarewin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@softwarewin](https://www.ruby-forum.com/u/softwarewin)\
**Post date:** [July 10, 2009, 2:56pm UTC](https://www.ruby-forum.com/t/find-conditions-cond-selection/171875/1 "2009-07-10T14:56:21Z")

</div>

Hi,  
I need to build these conditions to find items in the DB:

cond\_selection = { }  
cond\_selection[:public]=true  
(cond\_selection[:license\_id]=1 OR cond\_selection[:license\_id]=3)

@guides=Guide.find(:all,:order=\>‘title’,:conditions=\>cond\_selection)

* * *

In other words, I need to collect all the items that have license\_id=1  
OR license\_id=3.

This string:  
cond\_selection[:license\_id]=1 OR cond\_selection[:license\_id]=3  
doesn’t work!

How can I do?

Thank you very much!

Luigi

---

<div class="post-metadata">

**Author:** ![softwarewin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@softwarewin](https://www.ruby-forum.com/u/softwarewin)\
**Post date:** [July 14, 2009, 3:05pm UTC](https://www.ruby-forum.com/t/find-conditions-cond-selection/171875/2 "2009-07-14T15:05:36Z")

</div>

> This string:  
> cond\_selection[:license\_id]=1 OR cond\_selection[:license\_id]=3  
> doesn’t work!

Hmm. Perhaps better asked in the rails list but I’ll give it a shot.

since it’s two values for one variable, and a hash maps one to one,  
you’ll need to use an array [sorry]–at least AFAIK.

So  
cond\_selection = [“public = ? and (license\_id = ? or license\_id = ?)”,  
true, 1, 3]

something like that.  
I’m sure there are helpers out there to make that less annoying to use,  
though I don’t see any listed as gems per se.  
GL.  
=r
