Runnable demo.
When table 'foo' is in a one-to-many relationship with table 'bar', you can:
Output:
my $foo_rs = $schema->resultset('Foo')->search(
{},
{
join => 'bars',
prefetch => 'bars',
order_by => 'me.id',
}
);
while (my $foo = $foo_rs->next) {
printf "%s\n", $foo->id;
if (my $bar_rs = $foo->bars) {
while (my $bar = $bar_rs->next) {
printf " %s\n", $bar->desc;
}
}
}
Still one SQL statement against the database (fast!). Much prettier than ugly manual de-duping of redundant columns.
1
2
aaa
bbb
ccc
3