Rails AREL .where 语句 [英] Rails AREL .where statement

查看:51
本文介绍了Rails AREL .where 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 AREL 查询:

I have an AREL query:

@group.members.where('member_id != ?', 4)

正如预期的那样,此查询返回 ID 不等于 4 的所有成员.

As expected, this query returns all members with an ID not equal to 4.

我将如何构建相同类型的查询以省略多个 ID?例如:

How would I build the same type of query to omit multiple IDs? For example:

@group.members.where('member_id != ?', [4 3])

理想情况下,这将返回 ID 不等于 4 或 3 的所有成员.

Which would ideally return all members with an ID not equal to either 4 or 3.

推荐答案

正确的语法是:

@group.members.where('member_id NOT IN (?)', [4, 3] )

如果你只传递一个整数(不是数组),这也有效:

This also work if you pass only one integer (not an array):

@group.members.where('member_id NOT IN (?)', 12)

这篇关于Rails AREL .where 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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