[Rails] Find non-empty association?

Norman Timmler lists at inlet-media.de
Wed Mar 1 11:42:08 GMT 2006


Am Mittwoch, den 01.03.2006, 04:14 -0700 schrieb Pat Maddox:
> I have two models, Category and Article.  Article belongs_to :category
> and Category has_many :articles.  I'd like to be able to find all
> non-empty categories.  What's the best way to do that?

Category.find(
  :all,
  :include => :articles,
  :conditions => 'articles.category_id IS NOT NULL'
)

I think this might be the right clause. But i am not 100% sure.

-- 
Norman Timmler

http://blog.inlet-media.de



More information about the Rails mailing list