Hello,
I’m attempting to move beyond the Agile Web Dev w\Rails book and explore
writing some practice apps from scratch. I m attempting to model an
online t-shirt shop were customers can select from a variety of
different designs. Each design will be available in different colors
and each color will have different sizes. Also, I’d like to keep track
of the number of available shirts.
My most recent data modeling attempt consists of 3 tables and respective
columns:
- designs - name, description, picture, price.
- color - color, design_id
- size - size, color_id
The model associations are:
design - has_many :colors, has_many :sizes
color - has_many :sizes, belongs_to :designs
size - belongs_to :color, :belongs_to :design
SO far, so good! The problem is having to keep an inventory of the
number of available shirts (i.e. quantity). I have a 4th table called
‘quantity’ which has the following columns: quantity, design_id,
color_id, size_id since it isn’t strictly associated with a single
design, color or size but all three.
But… From here I’m lost. I have tried using a HABTM association
between the design table and quantity table but something just didn’t
seem right. So I’m asking for help. What is the best way to model
this? Does the ‘quantity’ table need to be on it’s own or can I perhaps
rework it into the other 3 tables?
Any help is greatly appreciated!!!