【发布时间】:2026-01-31 01:25:01
【问题描述】:
我的应用程序中有在线订购功能,我想提取所有在上周未提交订单的:clients(我有一个字段 :submitted_at 要跟踪这个)。
class Order < ApplicationRecord
belongs_to :client
scope :within_last_week, -> { where("submitted_at >= ?", 1.week.ago )}
end
class Client < ApplicationRecord
has_many :orders
end
我几乎希望能够使用这个:within_last_week 范围并返回orders.within_last_week 为空的客户。
有没有办法在不遍历所有客户端的情况下做到这一点?
【问题讨论】:
标签: ruby-on-rails associations