Rails 4 是否支持 OR 查询

编程入门 行业动态 更新时间:2024-10-27 01:27:26
本文介绍了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 查询

本文发布于:2023-10-24 15:00:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524251.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!