开发者

'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 
开发者_Python百科

I think I must use find_by_sqlnop ?


I believe this is the way:

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜