Rails,如何在示波器之间使用“或"运算符链接示波器? [英] Rails, how do I chain scopes with an “OR” operator between them?

查看:136
本文介绍了Rails,如何在示波器之间使用“或"运算符链接示波器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个从"".

在接受的答案中,代码示例生成的SQL看起来像这样:

In the accepted answer, the code example generates SQL looking something like:

"where 'age' similar to '%(foo|bar)%' AND 'name' similar to '%(foo|bar)%' AND

...等等.

如果要使用OR而不是AND链接作用域,如何实现呢?

How would I implement this if I want to chain the scopes with OR instead of AND?

推荐答案

检查any_of宝石.

让您执行以下操作:

banned_users      = User.where(banned: true)
unconfirmed_users = User.where("confirmed_at IS NULL")
inactive_users    = User.where.any_of(banned_users, unconfirmed_users)

这篇关于Rails,如何在示波器之间使用“或"运算符链接示波器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆