Relational Database Design (E-Commence) - Core Data

1.3k views Asked by At

In my e-commence app (for café/restaurants) I currently have the following database structure.

enter image description here

The cart is the shopping cart, in which you can add products, a temporary place before the products/an order is sent to the server. The ProductCart is a line item, many products (could be the same) with the different quantities, sizes, frying levels etc. When a order is sent, the cart is cleared and the products in the cart is transfered to the ProductOrder entity (an Order).

I now want to extend this further, with the ability of the products having ingredients and this is where it gets tricky and too complex for my head and database skills :-). As well as the (same) products can have different sizes and frying levels (hence the line item) a product should have the ability to have many different ingredients (add ons) for example a pizza, where you could choose the topping. This is what I have tried so far:

enter image description here

But I am not sure if this is the right structure or way to do it?

2

There are 2 answers

2
Mundi On

There is something fundamental you have not grasped about Core Data. Your ProductOrder entity is essentially a join table. This is completely unnecessary if you are not tracking additional attributes in this table.

Instead, you should have a many-to-many relationship between Order and Product.

It might seem that ProductCart satisfies my condition above that in this case a join table makes sense. But no - you should simply add the orders to your cart and track all the information in the Order entity.

2
Lorenzo B On

This is my suggestion.

Remove ProductOrder and Order entities. They are the same as ProductCart and Cart.

Now ProductCart should have an attribute like synchronized that is 1 or 0 based if it has been sent to server or not.

Through this you should simplify a lot your model. About Ingredient… entities they seem ok to me.