Howdy!
First time poster, please forgive any transgressions!
Our company is moving from Class::DBI to DBIx::Class after many years of using the former. Anyway, I've been working my way through the tutorials and have a question about writing a drill down procedure, it was very easy in Class::DBI. Here's a snippet from the beginner's guide:

#!/usr/bin/perl use strict; use Music::Artist; my ($artist) = Music::Artist->search_like(name => '%Beatles%'); print $artist->name,"\n"; foreach ($artist->cds) { print "\t", $_->title, "\n"; foreach my $track ($_->tracks) { print "\t\t", $track->songid->name,"\n"; } }
Here is the code I have working using DBIx::Class:The ## are to show what I've tried and the associated error message.
#!/usr/bin/perl -w use strict; use warnings; use lib qw( /usr/local/ActivePerl-5.16/lib /usr/local/ActivePerl-5.16/site/lib ); use MyDatabase::Main; my $schema = MyDatabase::Main->connect("dbi:mysql:dbname=test", "xxxxxxx", "XXXXXXX"); my $artistname = 'Michael Jackson'; my $rs = $schema->resultset('Artist')->search( { 'name' => ${artistname} }, ## If Join used: DBIx::Class::ResultSource::_resolve_join(): No +such relationship 'Cd' on Artist ## { ## join => { 'Cd' => 'Track' }, ## order_by => 'cd.title' , ## }, ); while (my $artist = $rs->next) { print "Artist: " . $artist->name . "\n"; ## Get: Can't locate object method "cd" via package "MyDatabase: +:Main::Result::Artist" ## print $artist->cd->title . "\n=======================\n"; my $cd_rs = $artist->search_related('cds', { artist => $artist-> +id }); while (my $cd_rec = $cd_rs->next) { print " " . $cd_rec->title . ".\n =======================\n +"; my $track_rs = $cd_rec->search_related('tracks', { cd => $cd_r +ec->cdid }); while ( my $track_rec = $track_rs->next) { print " " . $track_rec->trackid . ".) " . $track_rec->titl +e . ".\n"; } print "\n"; } } print "\n"; print "\n\nFinished.\n\n"; exit;

Is this the best practice for drilling down though DBIx::Class? Or am I using the wrong terminology? I've tried searching both Perlmonks and the internet to no avail.
Much Thanks in Advance!!


In reply to Proper way to drilldown using DBIx::Class? by ChuckP

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.