1
我想爲具有零個帖子的博客設置一個named_scope。在has_many關聯中爲「no children」創建一個named_scope
以下不起作用。
class Post < ActiveRecord::Base
belongs_to :blog
end
class Blog < ActiveRecord::Base
has_many :posts
named_scope :has_no_posts, :conditions => "blogs.id NOT IN (SELECT blog_id FROM posts)"
end