I am trying to create a e-commerce/shop system, I've decided to choose the class table inheritance design in SQL design based on this great answer.
Now I've got following table structure:
product ( id [PK], name, description )
product_shirt ( id [PK], product_id [FK], color, size, stock, price )
product_ring ( id [PK], product_id [FK], size, stock, price )
// maybe coming more
This works for representation of the products on a website. But if I wanted to place an order, of a few products how would this work?
If I had one table for my products I could assign the product_id as foreign key to a relation table, but with multiple tables this seems not possible anymore. Is it even possible with class table inheritance?
I've looked around alot, most answers/tutorial seem to concentrate on the representation of the products, but not on the order of a customer.
Drop fields
product_idfromproduct_shirtandproduct_ring, and make theiridfields both primary key and foreign key toproduct.id.Your
order_itemtable would contain a foreign key toproduct.id.When you need to pull information about products in a given order, make a query with a JOIN to
productonly. When you need the full details of a specific product, also JOIN with eitherproduct_shirtorproduct_ringdepending on the actual product type.Examples: