扶手:有,而不是AND或如何链范围查询?扶手、而不是、范围、AND

由网友(無理詩人)分享简介:我用Rails3,ActiveRecord的I'm using Rails3, ActiveRecord只是想知道我怎么能链中的作用域或语句,而不是和。Just wondering how can I chain the scopes with OR statements rather than 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).

阅读全文

相关推荐

最新文章