in reply to Many-to-many with Class::DBI

user: id name
item: id name
cart: user item
Tables user and item both have a primary key named id (i recommend you make this an auto incremented unsigned integer). The two fields in the cart table have their _id extensions removed because Class::DBI prefers them that way. They are still foreign keys associated with their respective tables' ids. With all of that out of the way, here is the (untested) code:
package CART::user; use base qw(CART::DBI); __PACKAGE__->table('user'); __PACKAGE__->columns(All => qw(id name)); __PACKAGE__->has_many(items => [qw(CART::item item)]); package CART::item; use base qw(CART::DBI); __PACKAGE__->table('item'); __PACKAGE__->columns(All => qw(id name)); __PACKAGE__->has_many(users => [qw(DVD::user user)]); package CART::cart; use base qw(CART::DBI); __PACKAGE__->table('cart'); __PACKAGE__->columns(Primary => qw/user item/); __PACKAGE__->has_a(user => 'DVD::user'); __PACKAGE__->has_a(item => 'DVD::item'); package main; for my $user (CART::user->retrieve_all) { my $items = $user->items; print $user->name; print " has no items\n" and next unless $items; print "has these items:\n"; print $_->name, "\n" for @$items; }
Better late than never. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)