【发布时间】:2009-06-16 21:30:40
【问题描述】:
假装我有一个模型,Post,其中 has_many :cmets。我怎样才能只显示有 cmets 的帖子?
我对 named_scope 有点满意,但我不知道如何将 Post.cmets(或 self.cmets)放入需要符号的 :conditions 哈希中。
class Post < ActiveRecord::Base
has_many :comments
named_scope :with_comments, :conditions => [#self.comments.length > 0]
end
我在评论区写什么?
谢谢!
【问题讨论】:
标签: ruby-on-rails activerecord named-scope