1

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?

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190

2 Answers2

1

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.

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
1

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.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • I agree with your answer but in this case those entities are not useful since can be collapsed by means of a boolean value. Anyway it's my personal advice. – Lorenzo B Jan 12 '14 at 23:31
  • My answer could include your or any other boolean value if that is deemed necessary or convenient. – Mundi Jan 12 '14 at 23:34