How to use OR condition in ActiveRecord query

后端 未结 5 1115
轻奢々
轻奢々 2020-12-09 02:38

I want to grab all the users that either have an email as the one supplied or the first and last name. So for example:

users = User.where(:first_name => \         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-09 02:45

    You could use string conditions, as in Client.where("orders_count = ? AND locked = ?", params[:orders], false), and use OR in conjunction with AND. Be careful with the priority of those operators though.

    Cf Active Record Query Interface guide

提交回复
热议问题