[Dbix-class] has_many relationships

Dan Horne dan.horne at redbone.co.nz
Mon May 1 22:11:25 CEST 2006


From: bluefeet at gmail.com [mailto:bluefeet at gmail.com]
> 
> $cd->tracks() returns a resultset.  If you want to get at the 
> title of the tracks do something like this:
> 
> my $tracks_rs = $cd->tracks();
> while (my $track = $tracks_rs->next()) {
>   print( $track->title() . "\n" );
> }

> A resultset by definition is a set, not a single record.  So, 
> retrieving a single field on a resultset is not a logical approach.
> 
> Aran
> 

Ahh! Ok, thanks, Aran

I think I got confused about the way a belongs_to relationship can access
the columns of both tables...

my $rs = $schema->resultset('Track')->search(
  {
    'cd.title' => $cdtitle
  },
  {
    join     => [qw/ cd /],
    prefetch => [qw/ cd /]
  }
);

my $track = $rs->first;
print $track->cd->title, ': ',$track->title, "\n";

... and now realise that this doesn't make sense in a has_many

Dan




More information about the Dbix-class mailing list