Commit | Line | Data |
5eb45f82 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use lib qw(t/lib); |
6 | use DBICTest; |
7 | |
1ec6e7c2 |
8 | plan tests => 7; |
5eb45f82 |
9 | |
10 | my $schema = DBICTest->init_schema(); |
11 | |
12 | my $cd_rs = $schema->resultset('CD')->search ( |
13 | { 'tracks.cd' => { '!=', undef } }, |
14 | { prefetch => ['tracks', 'artist'] }, |
15 | ); |
16 | |
17 | |
18 | is($cd_rs->count, 5, 'CDs with tracks count'); |
19 | is($cd_rs->search_related('tracks')->count, 15, 'Tracks associated with CDs count (before SELECT()ing)'); |
20 | |
21 | is($cd_rs->all, 5, 'Amount of CD objects with tracks'); |
22 | is($cd_rs->search_related('tracks')->count, 15, 'Tracks associated with CDs count (after SELECT()ing)'); |
23 | |
24 | is($cd_rs->search_related ('tracks')->all, 15, 'Track objects associated with CDs (after SELECT()ing)'); |
1ec6e7c2 |
25 | |
26 | my $artist=$schema->resultset('Artist')->create({name => 'xxx'}); |
27 | my $artist_rs = $schema->resultset('Artist')->search({artistid => $artist->id}, {prefetch=>'cds'}); |
28 | is($artist_rs->related_resultset('cds')->count, 0, "No CDs on a brand new artist"); |
29 | is($artist_rs->count, 1, |
30 | "No CDs prefetched but the artist is still returned"); |
31 | |