我一直在尝试为该模型编写一个范围,以帮助过滤和查找所有参与者(has_many 关系)都具有 recognize_at 值的记录。我遇到的问题是,当尝试这样做时,我得到了所有记录,其中至少一个参与者具有 recognize_at 值。我如何调整此范围以仅返回所有参与者在acknowed_at中都有值的范围?
涉及范围:
scope :completed, -> { joins(:example_participants).where('example_participants.acknowledged_at is not null') }
我已尝试通过几种方式反转和更改此设置,但尚未获得过滤掉目前只有一名参与者已确认的记录的结果。
重申我的目标是只记录所有参与者在acknowed_at
中存在的值我会从另一个方向做。
scope :completed, -> {
where.not(id: ExampleParticipant.select(:this_model_id).where(acknowledged_at: nil))
}