How to select where ID in Array Rails ActiveRecord without exception

前端 未结 6 812
余生分开走
余生分开走 2020-12-07 16:13

When I have array of ids, like

ids = [2,3,5]

and I perform

Comment.find(ids)

everything works fine. But w

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 16:44

    If you need more control (perhaps you need to state the table name) you can also do the following:

    Model.joins(:another_model_table_name)
      .where('another_model_table_name.id IN (?)', your_id_array)
    

提交回复
热议问题