I would have to suggest adding a proper primary key (auto increment field or similar). The primary key has to identify a single record in the table doesn't it? So your primary key in this case would need to consist of both the user_id and item_id fields.

Not sure what you're building the cart for, but I discovered early on that you'll also then come to grief if you had say different sizes, colours, etc for an item which might mean that a customer will want to have 2 of the same item in their cart (different colours or sizes).

The idea of a "junk" field is actually a good one, and I wouldn't call it junk. In the future you will probably find it very handy to have an id that simply identifies the record and doesn't really relate to the data in the record. I've learnt this way too late, and am slowly converting lots of tables to include this.

The other field I'd recommend is a timestamp that is updated whenever the record is added/changed so that it's easy to tell how long it's been since it's been accessed.

cheers,

J


In reply to Re: Many-to-many with Class::DBI by edoc
in thread Many-to-many with Class::DBI by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.