How do you do an or
query in Rails 5 ActiveRecord? Also, is it possible to chain or
with where
in ActiveRecord queries?
Ruby-on-rails – Rails 5: ActiveRecord OR query
activerecordrails-activerecordrubyruby-on-railsruby-on-rails-5
Related Topic
- Ruby-on-rails – Understanding the Rails Authenticity Token
- Ruby-on-rails – Rails :include vs. :joins
- Ruby-on-rails – How to get the current absolute URL in Ruby on Rails
- Ruby-on-rails – How to redirect to a 404 in Rails
- Ruby-on-rails – ActiveRecord OR query
- Ruby-on-rails – How to delete an ActiveRecord object
- Ruby-on-rails – Rails where condition using NOT NIL
- Ruby-on-rails – Getting error: Peer authentication failed for user “postgres”, when trying to get pgsql working with rails
Best Answer
The ability to chain
or
clause along withwhere
clause inActiveRecord
query will be available in Rails 5. See the related discussion and the pull request.So, you will be able to do the following things in Rails 5:
To get a
post
withid
1 or 2:Some other examples:
(A && B) || C:
(A || B) && C: