Rails/ActiveRecord: Syntax for “or” conditions? – Education Career Blog

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

,

You can do that in :condition options

User.all(:conditions => 'xxx= ? OR yyy=?', x_valu, y_value)

Leave a Comment