How to select where ID in Array Rails ActiveRecord without exception

前端 未结 6 798
余生分开走
余生分开走 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:53

    You can also use it in named_scope if You want to put there others conditions

    for example include some other model:

    named_scope 'get_by_ids', lambda { |ids| { :include => [:comments], :conditions => ["comments.id IN (?)", ids] } }

提交回复
热议问题