.setNegative(true)
如何在rails查询中查找具有多个注释的帖子?
答案 0 :(得分:5)
下面的查询应该可以使用
EXEC sp_MSForEachTable 'SELECT ''?'' as TableName, ID, rowid_time FROM ?'
答案 1 :(得分:3)
最优雅的方法是使用滑轨counter-cache
您要做的第一件事是,将comments_count
列添加到Post
模型中,并在Comment
模型中添加以下内容,
belongs_to :post, :counter_cache => true
因此,您可以获得如下评论大于1的帖子,
Post.where('comments_count > ?', 1)
这是实施的方式。