Rails AREL .where statement

后端 未结 1 1170
温柔的废话
温柔的废话 2021-01-20 05:16

I have an AREL query:

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

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

1条回答
  •  一整个雨季
    2021-01-20 05:27

    The correct syntax is:

    @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)
    

    0 讨论(0)
提交回复
热议问题