Subscriptions
canceled_at: ["2017-04-07T09:52:17-05:00", "2017-04-01T09:52:17-05:00"]
Canceled_at是一个字符串数组。每个元素都是转换为字符串的DateTime。
以上是我的订阅表。我正在尝试查询并查找在给定周内具有cancel_at日期的记录。
date = Date.today
Subscription.where("ANY subscriptions.canceled_at
BETWEEN '#{date.beginning_of_week(:sunday)}'
AND '#{date.end_of_week(:sunday)}'"
ruby 2.3.1p112
答案 0 :(得分:5)
Subscription.where(canceled_at:(date.beginning_of_week(:sunday)..date.end_of_week(:sunday)))
编辑:缺少右括号