0

I am coding a fast food system but I am having trouble at making the database logic. The business is small so the database shouldn't be too complex. They sell burgers but they want to make their hamburgers combos like mcdonalds does.

For example Combo #1 includes:

  1. 1 deluxe burger
  2. 1 Ice cream
  3. 1 pepsi
  4. and so on...

I want to store all Combos in the Food_Combos table with its detail inside in Detail_Combo . Product table are the products like Ice creams, coke, French fries, etc, that will be inside Detail_Combo .

When Combos are done... I can make a sale in a POS layout.

This is my database logic:

enter image description here

But the problem I am facing is that what if a customer wants to buy a single burger? ( not a combo ), I do not know how to make relationships because Food_Combos is liked to Detail_Sales.

How do I achieve this? Do I have to link Product to Detail_Sales too?

EthernalHusky
  • 485
  • 7
  • 19
  • 3
    if you have no problems with combos and you have problems with single items, then the solution is to make everything a combo ... single burger is just a combo with zero fries and zero drink – jsotola Oct 27 '20 at 03:02

1 Answers1

0

I'm not sure the difference between Food_Combos and Detail_Combo or how your sales tables are structured.

I would have a nullable column in the sales table for a combo Id, and only populate it if the item was purchased as part of a combo. In each sales record you would see the item that was purchased, and whether or not it was part of a combo.

One sale could then be a combo (burger, combo #1), (fries, combo #1), (drink, combo #1) and extra order of (apple pie, null combo reference).

ProductId    Description  
1            Burger  
2            Drink  
3            Fries  
4            Apple Pie  

ComboId      ProductId  
1            1  
1            2  
1            3

SaleProduct  ComboId  
1            1  
2            1  
3            1  
4            NULL  
  • 1
    Is this a good practice to leave null the spaces? Who downvoted this? – EthernalHusky Oct 27 '20 at 03:37
  • Yes. It is common and necessary in some cases. See this answer for more explanation on null foreign keys. https://stackoverflow.com/questions/7573590/can-a-foreign-key-be-null-and-or-duplicate – mister_smythers Oct 27 '20 at 05:08