[CDBI] Many to many help

Mike McKay mike at vdomck.org
Mon Aug 1 09:38:05 BST 2005

I need some help with a Many to Many situation. I have two tables, 
passenger and route, which are in a many to many relationship via a 
PassengerRouteJoin table. I followed the perldoc for Class::DBI to 
create the many to many relationship using inflation. But it doesn't 
work. Here is basically what I am doing:

PassengerRouteJoin->has_a(passenger => "Passenger");
PassengerRouteJoin->has_a(route => "Route");

Route->has_many(passengers => [ "PassengerRouteJoin" => 'passenger' ]);
Passenger->has_many(routes => [ "PassengerRouteJoin" => 'route' ]);

So then I try and do this:

my $p = Passenger->create({surname => "Blah", first_name => "Foo"}); 

my $r = Route->create({departure_point => "Lilongwe", destination => 

$p->add_to_routes({route => $r});

Can't deflate route: 8 is not a Route at 
/usr/local/share/perl/5.8.4/Class/DBI/Relationship/HasA.pm line 87

I have also tried this:

my $p = Passenger->create({surname => "Blah", first_name => "Foo"}); 

$p->add_to_routes({departure_point => "Lilongwe", destination => "Likoma"});

destination is not a column of PassengerRouteJoin at 
/usr/local/share/perl/5.8.4/Class/DBI/Relationship/HasMany.pm line 89

Any suggestions?


More information about the ClassDBI mailing list