比方說,我有模型,如下所示:如何按關聯計數過濾?
class Foo < ActiveRecord::Base
has_many :bars, :through => :cakes
has_many :cakes
end
class Bar < ActiveRecord::Base
has_many :foos, :through => :cakes
has_many :cakes
end
class Cake < ActiveRecord::Base
belongs_to :foo
belongs_to :bar
end
我怎麼會得到所有的Foo其中有10個或更多的酒吧(因此10分或更多的蛋糕)?
可以加快這counter_cache。 Foo.find(:all,:conditions => ['foo.cake_count> 10']) – jonnii 2009-10-14 04:38:27