如何用OR而不是AND链接作用域查询? [英] How to chain scope queries with OR instead of AND?

查看:52
本文介绍了如何用OR而不是AND链接作用域查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails3,ActiveRecord

I'm using Rails3, ActiveRecord

只是想知道如何使用OR语句而不是AND链接作用域。

Just wondering how can I chain the scopes with OR statements rather than AND.

例如

Person.where(:name => "John").where(:lastname => "Smith")

通常返回:

name = 'John' AND lastname = 'Smith'

但我想像:

`name = 'John' OR lastname = 'Smith'


推荐答案

您会这样做

Person.where('name=? OR lastname=?', 'John', 'Smith')

现在,新的AR3语法没有其他任何OR支持(即不使用某些第三方gem)。

Right now, there isn't any other OR support by the new AR3 syntax (that is without using some 3rd party gem).

这篇关于如何用OR而不是AND链接作用域查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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