I've been following the HABTM Railscast and am looking to extend it.
The Railscast way is great for adding categories to a product. But lets say I have (say) 5 ways of categorising products along different dimensions (and these change occasionally).
With the solution provided I would need to add 2 more models to my app each time I add a new 'dimension'.
Essentialy I want to move from a model like:
Product: Settlers of Catan
Categories: Board Games, Toys etc
to:
Product: Settlers of Catan
Category: Board Games, Toy etc
Age Range, 1-10, 11-20
Cost: High
The Railscast solution is here: http://railscasts.com/episodes/17-habtm-checkboxes-revised?view=comments
The existing solution, to be extended:
Product.rb
has many categorisations
has many categories, through categorisations
Categorisation.rb
belongs to many products
belongs to many categories
Category.rb
has many products, through categorisation
has many categorisations
I could do something like:
Product.rb
has many AgeRangeCategorisations
has many AgeRanges, through AgeRangeCategorisations
AgeRangeCategorisation.rb
belongs to many products
belongs to many AgeRanges
AgeRange.rb
has many products, through AgeRangeCategorisation
has many AgeRangeCategorisations
and
Product.rb
has many CostCategorisations
has many Costs, through CostCategorisations
CostCategorisation.rb
belongs to many products
belongs to many costs
Cost.rb
has many products, through CostCategorisation
has many CostCategorisations
But, it doesn't feel like the Rails way to create new models for each 'category type'.
I am think something along the lines of:
Product.rb
has many CategoryTypes
has many CategoryTypes, through CategoryTypeCategorisations
CategoryTypeCategorisations.rb
belongs to many Products
belongs to many CategoryTypes
CategoryType.rb
belongs to many CategoryTypeCategorisations
belongs to many categorisations
has many categories, through categorisations
Categorisation.rb
has many products
has many categories
Category.rb
has many products, through categorisation
has many categorisations
A CategoryType being the dimension (Age, Cost etc) and the category being the valid list of answers for the CategoryType.
This is getting a little confusing now with so many 'belongs to's and 'has many's floating about
Is this the correct way to try to approach this issue? How else could I approach this?