假装我有一个模型, Post 其中 has_many :comments。如何只显示有评论的帖子?
我对 named_scope 有点满意,但我不知道如何将 Post.comments(或 self.comments)放入需要符号的 :conditions 散列中。
class Post < ActiveRecord::Base
has_many :comments
named_scope :with_comments, :conditions => [#self.comments.length > 0]
end
我在评论区写什么?
谢谢!