|
An Introduction to Class::DBI - Table Relationships
|
30
|
|
|
Multi Table Relationships
Many to Many
Even though Person has many Films, these are only accessible using the Credit table as an intermediate:
print $actor->name . " acted in the following films: \n";
foreach my $credit ($actor->credits) {
my $film = $credit->film;
print $film->year , "\t", $film->title , "\n";
}
We can shorten this somewhat, but it's still awkward, if all we want is the films:
print $actor->name . " acted in the following films: \n";
foreach my $film (map { $_->film } $actor->credits) {
print $film->year , "\t", $film->title , "\n";
}
|
|