我知道这可以做到:
Article.where("published_at <= ?",Time.now).includes(:comments)
但是如果我想只收到过去一个月发表的评论怎么办?
.includes操作符是否允许条件?
解决方法
Article.includes(:comments).where("articles.published_at <= ? and comments.created_at >= ?",Time.now,Time.now - 1.month)
编辑:
Article.joins(:comments).where("articles.published_at <= ? and comments.created_at >= ?",Time.now - 1.month)