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?
Pat
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?
Pat
Am Mittwoch, den 01.03.2006, 04:14 -0700 schrieb Pat M.:
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 T.
On 3/1/06, Norman T. [email protected] wrote:
Thanks for the code bit. Unfortunately I’m not sure if it works,
because I’m using HABTM. Of course it was late and didn’t ask the
proper question…but is there a nice way to do it for a HABTM?
Pat
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs