【问题标题】:Compare dates along with other constraints in ActiveRecord query在 ActiveRecord 查询中比较日期和其他约束
【发布时间】:2016-10-17 08:35:24
【问题描述】:

我正在尝试获取大于另一个日期的空间列表日期。

到目前为止,我已经...

    Booking.where({ space_listing_id: 22, approved_status: true, ['move_out < ?', potential_move_in] })

我需要检查 Booking 的潜在日期是否大于每个带有 move_out 日期的 space_listing。

我的 move_out 和 move_in 是一个日期时间。

【问题讨论】:

  • stackoverflow.com/a/4224627/2545197 这个答案应该有帮助
  • 谢谢阿比奈。它现在正在工作。我做了 Booking.where("move_out
  • 与另一个where 查询..您的问题的答案本身就在那里。
  • 谢谢你,阿比奈。
  • 如果有帮助请接受我的回答。

标签: ruby-on-rails postgresql activerecord


【解决方案1】:

为了在 ActiveRecord 查询中组合多个约束,您可以简单地使用多个 where 子句。

Booking.where(space_listing_id: 22, approved_status: true).where("move_out < ?", potential_move_in)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-03
    • 2018-03-20
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    相关资源
    最近更新 更多