[Dbix-class] has_many relationships
Dan Horne
dan.horne at redbone.co.nz
Mon May 1 21:39:45 CEST 2006
Hi all
I'm don't quite understand how to do joins in a "has many" context, and why
it works differently from a "belongs_to" equivalent. Take, for example the
music schema in Example.pod
(http://search.cpan.org/~elliott/DBIx-Class-0.06002/lib/DBIx/Class/Manual/Ex
ample.pod). The following query works (where CDs have many Tracks):
sub get_cd_by_track {
my $tracktitle = shift;
print "get_cd_by_track($tracktitle):\n";
my $rs = $schema->resultset('Cd')->search(
{
'tracks.title' => $tracktitle
},
{
join => [qw/ tracks /],
}
);
my $cd = $rs->first;
print $cd->title . "\n\n";
}
This all works, but if I try to add the track title to the query:
print $cd->tracks->title . "\n\n";
I get:
Can't locate object method "title" via package "DBIx::Class::ResultSet"
How do I also get the track title from the resultset?
Dan
More information about the Dbix-class
mailing list