Hier die betreffenden Relationen:
package Bulletinboard::Schema::Topic;
use strict;
use warnings;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/ PK::Auto Core /);
__PACKAGE__->table('topics');
__PACKAGE__->add_columns(qw/topic_id topic position/);
__PACKAGE__->set_primary_key('topic_id');
__PACKAGE__->has_many(boards => 'Bulletinboard::Schema::Board', 'board_id');
1;
package Bulletinboard::Schema::Board;
use strict;
use warnings;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/ PK::Auto Core /);
__PACKAGE__->table('boards');
__PACKAGE__->add_columns(qw/board_id topic_id title position description/);
__PACKAGE__->set_primary_key('board_id');
__PACKAGE__->belongs_to(topic => 'Bulletinboard::Schema::Topic', 'topic_id');
__PACKAGE__->has_many(threads => 'Bulletinboard::Schema::Thread', 'thread_id');
1;
Wenn ich jetzt irgendwo im Code alle Boards von einem Topic aufrufe kommt nix zurück:
my $rs = $schema->resultset('Topic')->search(undef);
foreach my $t ( $rs->all() ) {
say "t: " . $t->topic();
# geht
my $brs = $schema->resultset('Board')->search({topic_id => $t->topic_id()});
say "board count: " . $brs->count();
# geht nicht
my $boards = $t->boards();
say "board count: " . $boards->count();
}
Ausgabe:
Quotet: 1
board count: 0
board count: 0
t: 2
board count: 1
board count: 0
t: 3
board count: 0
board count: 0