我该如何仅抓取20分钟前创建的带有评论的文章? [英] How would I grab only articles with comments that were created 20 minutes ago?
本文介绍了我该如何仅抓取20分钟前创建的带有评论的文章?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用mongodb和mongoid.一个人怎么抓所有文章.仅20分钟前创建评论的文章?
Using mongodb and mongoid. How would one grab all articles. Only articles with comments created 20 minutes ago?
class Article
include Mongoid::Document
has_many :comments
end
class Comment
include Mongoid::Document
belongs_to :article
end
推荐答案
您也可以执行此操作,这应该更有效:
you can also do this, which should be more efficient:
articles = Article.where(:"comments.created_at".gt => 20.minutes.ago)
这篇关于我该如何仅抓取20分钟前创建的带有评论的文章?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文