Thread DBIx::Class - alle Akzessoren ausgeben (8 answers)
Opened by pktm at 2009-01-06 01:22

pktm
 2009-01-06 02:00
#117601 #117601
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
Hier die betreffenden Relationen:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;


Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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:
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
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:
Quote
t: 1
board count: 0
board count: 0
t: 2
board count: 1
board count: 0
t: 3
board count: 0
board count: 0
http://www.intergastro-service.de (mein erstes CMS :) )

View full thread DBIx::Class - alle Akzessoren ausgeben