One way Has-Many-Through
- by Hock
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