0

I want to let a user create a food schedule(schema table) let him create his own food (userProduct) or choise from the supermarkets(supermarketproduct)

the user should be able to make many food schedules(schemas) and should be able to include many userproducts or many supermarketproducts. Both of them can be in one food schedule but, i do not know how to implement an many to many relationship with this because if i include both userproduct and supermarket product one of them will always be null.

database picture

Solution:

enter image description here

0

I would have a combined Product table with all common elements (name, protein, etc) and this would tie to the food schedules. Then there would be two additional tables for ProductUser and ProductMarket that would refer back to the main Product table. No nulls needed and it's nice and normalized.

  • but woulnt that mean that a forgein key has to be placed in supermarketproduct which means all those vields will be duplicate everytime ? – user3244534 Dec 13 '17 at 0:08
  • no, supermarket product will not contain protein, carbs, fat, or name. It will only have a reference to product.productid, the price, and supermarket.supermarketid. – indiri Dec 13 '17 at 0:13
  • Like in the picture i just updated on the post? – user3244534 Dec 13 '17 at 0:57
  • Yes, that's what I was thinking – indiri Dec 13 '17 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.