SQL/PHP: Table design question -


I have two tables, called a "cart" and what I call "items" That the cart be able to store a "item" and a list of quantities. That's why I have created another table "cart_items" which contains the ID of the template, the ID of the item and the quantity.

Is this a good design, or should I add another area for the ID of "cart_itim"? Or is there a better way to do it all together? When I try to update my car, I am just running in trouble, my cart items do not update properly, what am I going to do all "cart_times" by car Is connected and then to re-add each "cart_item" and I can not help but it seems that there should be a better way

This is a very good design.

In the words ER (unit relationship) there are many relationships between objects and cart, through this I mean that an item can appear in many different trains and many different in a cart - Different items may be included In this context "many" is a "one variable number that can be more than one".

Your cart_ts are called table joining the table and you need to model many-to-many relationships. Added Quantity field also understands it as it puts it on Cart_Items.

You have two options for the key:

  1. Make (the cart_id, item_id) primary key. This is called an overall primary key; Or
  2. Creating an auto increment field named ID If you do this (Cart_ID, Item_ID) a unique index to implement the specification.

Either choice is valid personally I like (2) You must also have a unique index on all possibilities (item_id, cart_id).


Comments

Popular posts from this blog

c# - PInvoke of NetUserAdd returns 24 -

NHibernate Passing Session to the Repository -