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

查看:22
本文介绍了如何使用 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 支持(即不使用某些 3rd 方 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天全站免登陆