Hartator
Hartator

Reputation: 5145

'Or' Operator in Active Record?

Does it exist an OR operator in RoR ? I want or archieve something like this :

Model.where('cat_id' => 5 OR 'color' => 'grey').all 

I think I must use find_by_sqlnop ?

Upvotes: 2

Views: 1206

Answers (2)

user483040
user483040

Reputation:

You might consider looking at the MetaWhere gem. It supports compound conditions with syntax like this:

Article.where(:title.matches % 'Hello%' | :title.matches % 'Goodbye%')

It has a lot more to it than just that but it is a really great gem to augment Arel.

Upvotes: 3

Wukerplank
Wukerplank

Reputation: 4176

I believe this is the way:

Model.where('cat_id=? OR color=?', 5, 'grey')

Upvotes: 6

Related Questions