Rails 4 是否支持 OR 查询 [英] Does Rails 4 have support for OR queries

查看:31
本文介绍了Rails 4 是否支持 OR 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此在 Rails 4 中添加了使用not 查询的长期期望的功能.

So in Rails 4 the long desired feature to use not queries has been added.

Article.where.not(title: 'Rails 3')

是否为 查询添加了类似的支持,或者他们是否计划实现.我通过浏览发行说明找不到任何内容.

Has similar support been added for or queries, or are they planning to make it. I couldn't find anything by browsing through the release notes.

显然我试过了

Article.where(title: 'Rails 3').or(title: 'Rails 4')

但这行不通.

推荐答案

Article.where(title: ['Rails 3', 'Rails 4'])

就是你在 Active Record 中的做法.

is how you'd do that in Active Record.

不可能使用Rails-y"语法复制任何任意 SQL 查询.但是你总是可以只传入文字 sql.

It's not possible to replicate any arbitrary SQL query using "Rails-y" syntax. But you can always just pass in literal sql.

所以你也可以这样做:

Article.where("articles.title = 'Rails 3' OR articles.title = 'Rails 4'")

这篇关于Rails 4 是否支持 OR 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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