ActiveRecord查询使用包含和限制日期

时间:2016-12-15 05:25:15

标签: ruby-on-rails postgresql ruby-on-rails-4 activerecord

我试图显示预订的@ratings,只要它的“结束”字段小于Time.now。

这有效(但没有时间限制):

@ratings = Rating.where(user_id: current_user.id).includes(:reservation).includes(:room)

我正在尝试使用“reservations.end< Time.now”限制查询,如下所示:

@ratings = Rating.where(user_id: current_user.id, reservations.end < Time.now).includes(:reservation).includes(:room)

但它不起作用。

1 个答案:

答案 0 :(得分:2)

@ratings = Rating.includes(:reservation, :room).where(user_id: current_user.id).where("reservations.end < ?", Time.now)