hi...
The query below is based on the DBIx::Class::Manual::Example,
sub get_cds_by_artist
{
print "cd by artist: \n";
my $name = shift;
my $rs = $schema->resultset('Artist')->search(
{
'me.name' => $name
},
{
join => [qw/ cds /],
prefetch => [qw/ cds /]
}
);
while( my $artist = $rs->next)
{
print $artist->cds->title . "\n\n";
}
}
The app is throwing the following error:
Can't locate object method "title" via package "DBIx::Class::ResultSet"
If I am not wrong, the accessors are not being created...
Could somebody help me out with this.
Schema:
--------------------------------------------------------
package Main::Artist;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('artist');
__PACKAGE__->add_columns(qw/ artistid name /);
__PACKAGE__->set_primary_key('artistid');
__PACKAGE__->has_many('cds' => 'Main::Cd');
1;
package Main::Cd;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('cd');
__PACKAGE__->add_columns(qw/ cdid artist title/);
__PACKAGE__->set_primary_key('cdid');
__PACKAGE__->belongs_to('artist' => 'Main::Artist');
---------------------------------------------------------
PS:
This works fine :
my $rs = $schema->resultset('Cd')->search(
{
'artist.name' => $artistname
},
{
join => [qw/ artist /],
prefetch => [qw/ artist /]
}
);
but what I am looking for, is to query on the class defining the
'has_many' relationship.
_______________________________________________
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/[email protected]/