91b1fb7daf3df905224de4903f53aeb3de211070
[dbsrgits/DBIx-Class.git] / t / search / related_has_many.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 use lib qw(t/lib);
7 use DBICTest;
8
9 my $schema = DBICTest->init_schema();
10
11 my $cd_rs = $schema->resultset('CD')->search ({ artist => { '!=', undef }});
12
13 # create some CDs without tracks
14 $cd_rs->create({ artist => 1, title => 'trackless_foo', year => 2010 });
15 $cd_rs->create({ artist => 1, title => 'trackless_bar', year => 2010 });
16
17 my $tr_count = $schema->resultset('Track')->count;
18
19 my $tr_rs = $cd_rs->search_related('tracks');
20
21
22 my @tracks;
23 while ($tr_rs->next) {
24   push @tracks, $_;
25 }
26
27 is (scalar @tracks, $tr_count, 'Iteration is correct');
28 is ($tr_rs->count, $tr_count, 'Count is correct');
29 is (scalar ($tr_rs->all), $tr_count, 'All is correct');
30
31 done_testing;