Rails Console find users by array of ids

前端 未结 6 1484
清歌不尽
清歌不尽 2020-12-23 19:25

So I have an array of user ids. Is there a way in rails console to query all of these user\'s with the array

something like

ids = [1, 2, 3, 4]

users         


        
6条回答
  •  臣服心动
    2020-12-23 19:59

    you can use

       Users.where({ id: [1,2,3 ,4]})
     # SELECT * FROM users WHERE id IN (1,2,3,4)
    

提交回复
热议问题