![]() |
![]() |
9 Einträge, 1 Seite |
my $rs = $schema->resultset('Table')->search(undef);
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;
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;
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();
}
Quotet: 1
board count: 0
board count: 0
t: 2
board count: 1
board count: 0
t: 3
board count: 0
board count: 0
__PACKAGE__->has_many(boards => 'Bulletinboard::Schema::Board', { 'foreign.topic_id' => 'self.topic_id' } );
pktm+2009-01-06 01:36:38--Ah ja! Ich dachte, ich hätte in der Dokumentation gelesen, der dritte Parameter
renee+2009-01-06 08:48:47--Vielleicht hilft Dir auch http://renee-baecker.de/talks/DBIx_Class.pdf
pktm+2009-01-06 12:32:45--Aber wie gesagt, ich dachte, die explizite Version wäre hier überflüssig - ist sie aber nicht.
![]() |
![]() |
9 Einträge, 1 Seite |