[Dbix-class] DBIx::Class::Relationship issue

abhijith abhijithg at deeproot.co.in
Wed Mar 21 04:06:55 GMT 2007


On Tue, 2007-03-20 at 14:30 +0100, Michele Beltrame wrote:
> Hi!
> 
> >     while( my $artist = $rs->next)
> >     {
> > 	print $artist->cds->title . "\n\n";
> >     }
> 
> The "cds" relations is has_many, so you'll probably want to do this to display 
> all CD title of all artists:
> 
> while( my $artist = $rs->next) {
>      my $cds = $artist->cds;
>      while ( my $cd = $cds->next ) {
>          print $cd->title . "\n\n";
>      }
> }
> 
> If you only expect one CD per artist, you can do as follows:
> 
> while( my $artist = $rs->next) {
>      print $artist->cds->first->title . "\n\n";
> }
> 
> Michele.
> 
> _______________________________________________
> List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/

Guess I should focuss more on the fundamentals :)
Thanks for the solution Michele.





More information about the Dbix-class mailing list