扶手:有,而不是AND或如何链范围查询? [英] Rails: How to chain scope queries with OR instead of AND?

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

问题描述

我用Rails3,ActiveRecord的

I'm using Rails3, ActiveRecord

只是想知道我怎么能链中的作用域或语句,而不是和。

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

例如。

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

这是正常返回名称='约翰'和姓氏=史密斯,但我想:

That normally returns name = 'John' AND lastname = 'Smith', but I'd like:

名称='约翰'或姓氏=史密斯

name = 'John' OR lastname = 'Smith'

推荐答案

您会做

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

目前,还没有任何其他的或支持由新的AR3语法(即不使用一些第三方的宝石)。

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

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

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