开发者

'Or' Operator in Active Record?

开发者 https://www.devze.com 2023-03-13 23:08 出处:网络
Does it exist an OR operator in RoR ? I want or archieve something like this : Model.where(\'cat_id\' => 5 OR \'color\' => \'grey\').all

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

精彩评论

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