【问题标题】:ActiveRecord query using includes and restricting date使用包含和限制日期的 ActiveRecord 查询
【发布时间】:2016-12-15 05:25:14
【问题描述】:

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

这可行(但没有时间限制):

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

我正在尝试使用“reservations.end

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

但它不起作用。

【问题讨论】:

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


    【解决方案1】:
    @ratings = Rating.includes(:reservation, :room).where(user_id: current_user.id).where("reservations.end < ?", Time.now)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 2017-03-26
      • 2014-04-21
      • 1970-01-01
      • 2023-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多