How can I make an 'OR' statement in ActiveRecord?

前端 未结 2 808
暗喜
暗喜 2021-01-03 02:20

I am trying to create an \'OR\' sql statement in ActiveRecord 3, I tried all kinds of variations but can\'t figure it out...

For example I want this query to include

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-03 03:02

    Use the Arel methods to do this:

    t = Post.arel_table
    ids = [1,2,3]
    
    Post.where(
      t[:user].eq("mike").or(t[:channel_id].in(ids))
    )
    

提交回复
热议问题