File: related_has_many.t

package info (click to toggle)
libdbix-class-perl 0.082810-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,012 kB
  • ctags: 2,157
  • sloc: perl: 26,390; sql: 322; makefile: 10
file content (31 lines) | stat: -rw-r--r-- 711 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use strict;
use warnings;

use Test::More;

use lib qw(t/lib);
use DBICTest;

my $schema = DBICTest->init_schema();

my $cd_rs = $schema->resultset('CD')->search ({ artist => { '!=', undef }});

# create some CDs without tracks
$cd_rs->create({ artist => 1, title => 'trackless_foo', year => 2010 });
$cd_rs->create({ artist => 1, title => 'trackless_bar', year => 2010 });

my $tr_count = $schema->resultset('Track')->count;

my $tr_rs = $cd_rs->search_related('tracks');


my @tracks;
while ($tr_rs->next) {
  push @tracks, $_;
}

is (scalar @tracks, $tr_count, 'Iteration is correct');
is ($tr_rs->count, $tr_count, 'Count is correct');
is (scalar ($tr_rs->all), $tr_count, 'All is correct');

done_testing;