ActiveRecord where field = ? array of possible values

后端 未结 6 1160
無奈伤痛
無奈伤痛 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:35

    For readability, this can be simplified even further, to:

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

    This is equivalent to using where, but more explicit:

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

提交回复
热议问题