【发布时间】:2017-02-24 20:10:54
【问题描述】:
我正在做一个项目,我有一组帖子,一个帖子有很多 cmets,一个帖子还有一个 cmets_last_checked 字段和一个 comment_checking_threshold 字段。我需要能够获得在 cmets_last_checked 日期和当前日期之间的 cmets 数量超过其 comment_checking_threshold 的帖子。我不太确定如何执行此操作,因为每个帖子的阈值和日期范围会有所不同。
我有一些类似的东西:
@posts.joins(:comments
).where(comments: { 'comments.created_at > posts.comments_last_checked' }
).group('posts.id'
).having('COUNT(comments.id) >= posts.comment_checking_threshold')
但是我似乎无法让它工作。任何帮助将不胜感激。
编辑
我现在将代码更新为:
@posts.joins(:comments
).where('comments.created_at > posts.last_review_date'
).group('posts.id'
).having('posts.review_threshold >= COUNT(comments.id)')
但是我现在在“有子句”中收到错误未知列“posts.review_threshold”
【问题讨论】:
标签: ruby-on-rails ruby activerecord