I see it now. The orginal data defition doesn't use any primary keys on the join table at all. But I don't think making both fields primary keys is the right way to go. Instead, I usually create a third field that is a primary key all on its own:
mysql> create table user_role ( -> id int(11) not null primary key auto_increment, -> user_id int(11) not null default '0', -> role_id int(11) not null default '0', -> foreign key user_fk (user_id) references user (id), -> foreign key role_fk (role_id) references role (id) -> );
The OP's Class::DBI code was making user_id the primary key, which didn't match up the data definition either (All makes the first column specified the primary key). The new code should be:
__PACKAGE__->columns( All => qw/ id user_id role_id / );
With the has_a relationships that are noted in the orginal.
----
: () { :|:& };:
Note: All code is untested, unless otherwise stated
In reply to Re^6: many to many with Class::DBI
by hardburn
in thread many to many with Class::DBI
by jdtoronto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |