|
An Introduction to Class::DBI - Table Relationships
|
27
|
|
|
Multi Table Relationships
One to Many and One to One (has_a)
In SQL:
SELECT year, title, type
FROM person, credit, film
WHERE credit.person_id = person.id
AND credit.film_id = film.id
AND person.name = 'Harrison Ford';
In Class::DBI:
my ($actor) = FilmBuff::Person->search(name => 'Harrison Ford');
print $actor->name . " has the following credits: \n";
foreach my $credit ($actor->credits) {
print $credit->film_id->year , "\t",
$credit->film_id->title , "\t",
$credit->type, "\n";
}
|
|