0

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

PlankTon
  • 12,443
  • 16
  • 84
  • 153

1 Answers1

6

You can do that in :condition options

User.all(:conditions => ['xxx= ? OR yyy=?', x_valu, y_value])
shingara
  • 46,608
  • 11
  • 99
  • 105
  • Do you know of a list of examples anywhere of rails-sql statements? – Trip Oct 20 '10 at 13:07
  • 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 Oct 20 '10 at 14:16