One way Has-Many-Through

Posted by Hock on Stack Overflow See other posts from Stack Overflow or by Hock
Published on 2010-05-17T03:48:04Z Indexed on 2010/05/17 4:50 UTC
Read the original article Hit count: 279

Hello, I have a Category, a Subcategory and a Product model.

I have:

Category has_many Subcategories
Subcategory has_many Products
Subcategory belongs_to Category
Product belongs_to Subcategory

Is there a way to have something like

Category has_many Projects through Subcategories

?

The 'normal' rails way wouldn't work because "subcategory" doesn't belongs to product so product does not have a subcategory_id field. Instead, I need the query to be something like

SELECT * FROM products WHERE id IN category.subcategory_ids

Is there a way to do that?

Thanks,

Nicolás Hock Isaza

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about has-many-through