in reply to Many-to-many with Class::DBI
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
|
|---|