Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 264925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:43:34+00:00 2026-05-11T22:43:34+00:00

I have two tables, one called cart and one called items. Now I want

  • 0

I have two tables, one called “cart” and one called “items”. Now I want cart to be able to store a list of “items” and quantities. So I created another table “cart_items” that has a field for the id of the template, the id of the item and the quantity.

Is this good design, or should I add another field for the id of the “cart_item”? Or is there better way to do this all together? I’m just running in trouble when I try to update my cart my cart items don’t update correctly. What I’m having to do is delete all the “cart_items” attached to a cart and then re-add each “cart_item” and I can’t help but think there has to be a better way to do this.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:43:34+00:00Added an answer on May 11, 2026 at 10:43 pm

    That’s very good design.

    In ER (entity relationship) terms there is a many-to-many relationship between items and carts. By that I mean an item can appear in many different carts and a cart can contain many different items. “Many” in this context means “a variable number that can be more than one”.

    Your cart_items table is what’s called a join table and you need it to model many-to-many relationships. Added a quantity field also makes sense as does putting it on cart_items.

    You have two choices when it comes to the key:

    1. Make (cart_id, item_id) the primary key. This is called a composite primary key; or
    2. Creating an auto increment field called id. If you do this make (cart_id, item_id) a unique index to enforce uniqueness.

    Either choice is valid. Personally I prefer (2). You should also have a unique index on (item_id, cart_id) in all likelihood.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, one contains a list of items which is called watch_list
I have two tables on my database. One called room and another is called
I have two tables: one called Projects, and another called Documents (projects has many
I have two tables, one called PROJETO (id_projeto, id_tipo_projeto, descr_projeto, versao_projeto) and another called
I have two tables - one called customer_records and another called customer_actions . customer_records
I have two tables, one called items and one called bids. Bids contains a
So i'm having this problem. I have two tables (Oracle), one is called Destination
I have two tables. One (Widgets) has a list of widgets (ID, widget_name, color,
I have two tables, one called countries and one called country. Countries has both
I have two tables. One is temp table and another is main table. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.