ActiveRecord where field = ? array of possible values

后端 未结 6 1138
無奈伤痛
無奈伤痛 2020-12-13 07:47

I want to do

Model.where(\'id = ?\', [array of values])

How do I accomplish this look up without chaining OR statements together?

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 08:51

    From here it appears to be done using an SQL in statement:

    Model.where('id IN (?)', [array of values])
    

    Or more simply, as kdeisz pointed out (Using Arel to create the SQL query):

    Model.where(id: [array of values])
    

提交回复
热议问题