Given a simple case of two tables - Term and Definition - where Term has_many
Definitions and Definition belongs_to
Term, all terms and the corresponding definitions are to be fetched and displayed somehow.
Here is what I've come up with so far:
my $terms= $schema->resultset('Term')->search(undef, {
prefetch => 'definitions',
});
while (my $term = $terms->next) {
my @terms;
push @terms, $term->term;
my $definitions = $term->definitions;
my @definitions;
while (my $definition = $definitions->next) {
push @definitions, $definitions;
}
...
}
It does the job but I was wondering if a different, less crufty approach could be taken.