Answer the question
In order to leave comments, you need to log in
How to use logical operators in where queries in rails?
Continuation of the question How to pull out a post with comments on a specific date? :
As in a similar query:
@posts = Post.where(user_id:123).includes(:comments).where(comments: { created_at: Time.zone.today...Time.zone.tomorrow })
, add a similar condition, but on a different field using logical operators? @posts = Post.where(user_id:123).includes(:comments).where(comments: { created_at: Time.zone.today...Time.zone.tomorrow } | comments: { created_at: Time.zone.today...Time.zone.tomorrow })
Answer the question
In order to leave comments, you need to log in
Something like that.
The native ability to use the logical OR operator in ActiveRecord exists in Rails 5.
https://github.com/rails/rails/pull/16052
https://github.com/rails/rails/blob/aa3acf85cb/act...Post.where(id: 1).or(Post.where(id: 2))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question