Results 1 to 2 of 2
Aug 7, 2008, 12:56 #1
- Join Date
- Dec 2002
- Denver, CO
- 0 Post(s)
- 0 Thread(s)
Issue with selecting items based on category id
So I have a Categories table with top level categories and sub categories that have a parent_id column to associate the sub category to the top level.
I then have an Items table with a category_id that associates the item to the category. The category_id always points to a sub category.
How would I get all the items that are under a top level category?
As an example, say I have the following category setup:
All of the items point to the category id's of those sub categories, but I'm wanting to get all the items under "Photoshop".
Aug 8, 2008, 08:46 #2
Assuming you don't have sub-sub-categories, something very close to this should work:
parent_id = params[:category_id] @items = Items.find(:all, :conditions => ['category_id in (select id from category where parent_id = ?)', parent_id])