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:
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 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"; } }
#!/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;
In reply to Proper way to drilldown using DBIx::Class? by ChuckP
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |