views:

9

answers:

1

Hi folks,

Just trying to figure out how to write "or" statements in activerecord conditions without resorting to raw sql - I assume it can be done, but google isn't helping much.

So, to give an example, suppose there's a model "Author" with a one-to-many relationship with 'Books' and a many-to-one relationship with 'Publisher'. How would I find all authors who have a publisher with name "Penguin" OR a book released in 2010 (or both) without resorting to SQL?

Any suggestions much appreciated

+1  A: 

You can do that in :condition options

User.all(:conditions => ['xxx= ? OR yyy=?', x_valu, y_value])
shingara
@shingara Do you know of a list of examples anywhere of rails-sql statements?
Trip
It's just an SQL statement push on WHERE part where all ? are replace by escaping value. It's the first querying system before named_scope arrived
shingara