How to use OR condition in ActiveRecord query

后端 未结 5 1114
轻奢々
轻奢々 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条回答
  •  醉酒成梦
    2020-12-09 03:12

    Rails 5 comes with an or method.

    This method accepts an ActiveRecord::Relation object. eg:

    User.where(first_name: 'James', last_name: 'Scott')
        .or(User.where(email: 'james@gmail.com'))
    

提交回复
热议问题