活动记录where方法而不是 [英] active record where method and not

查看:73
本文介绍了活动记录where方法而不是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎在任何地方都找不到答案。我知道我可以做到:

I can't seem to find the answer to this anywhere. I know I can do:

Item.where(:color => 'red')

要获取所有红色项,但是如何获取所有颜色不是红色的项?

to get all red items, but how do I get all items whose color is not red?

推荐答案

这是旧学校格式和新Arel格式的混合。

It's a mix of the old school format and the new Arel format.

Item.where("color != ?", 'red')

这篇关于活动记录where方法而不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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