本文介绍了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 查询
发布评论