我在Rails application
使用加入查询,我获得了成功记录,但我需要fetch record
更新日期大于昨天日期或创建日期大于昨天。
如何查询OR between updated_date and created_date?
所以我解雇了下面的查询但发布了。
@courses = Course.includes(:translations).where(course_translations: {status: 'active'}, published: true, created_at: time_range, updated_at: time_range)
仍然没有得到任何解决方案。任何人都有想法,请与我分享。
答案 0 :(得分:0)
嘿,你可以试试这种方式
start_date = Time.zone.now.beginning_of_day
end_date = Time.zone.now.end_of_day
@courses = Course.includes(:translations).where(course_translations: {status: 'active'}, published: true).where("courses.created_at Between ? And ? or courses .updated_at Between ? And ?", start_date,end_date,start_date,end_date).
答案 1 :(得分:-1)
希望它能提供您想要的输出
Course.includes(:translations).where("course_translations.status =? and courses.published =? and (courses.created_at > ? or courses.updated_at > ?)",'active',true,Date.yesterday.end_of_day,Date.yesterday.end_of_day)
让我知道你的结果