find(:conditions=>cond_selection

L

Luigi Maresca

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,:eek:rder=>'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
 
R

Roger Pack

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top