Confirm prefetch doesn't affect main row fetch, and main row fetch works with and...
[dbsrgits/DBIx-Class.git] / t / prefetch / count.t
CommitLineData
5eb45f82 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
a7daf36a 8plan tests => 9;
5eb45f82 9
10my $schema = DBICTest->init_schema();
11
12my $cd_rs = $schema->resultset('CD')->search (
13 { 'tracks.cd' => { '!=', undef } },
14 { prefetch => ['tracks', 'artist'] },
15);
16
17
18is($cd_rs->count, 5, 'CDs with tracks count');
19is($cd_rs->search_related('tracks')->count, 15, 'Tracks associated with CDs count (before SELECT()ing)');
20
21is($cd_rs->all, 5, 'Amount of CD objects with tracks');
22is($cd_rs->search_related('tracks')->count, 15, 'Tracks associated with CDs count (after SELECT()ing)');
23
24is($cd_rs->search_related ('tracks')->all, 15, 'Track objects associated with CDs (after SELECT()ing)');
1ec6e7c2 25
26my $artist=$schema->resultset('Artist')->create({name => 'xxx'});
27my $artist_rs = $schema->resultset('Artist')->search({artistid => $artist->id}, {prefetch=>'cds'});
a7daf36a 28is($artist_rs->count, 1, "New artist found with prefetch turned on");
29is(scalar($artist_rs->all), 1, "New artist fetched with prefetch turned on");
30is($artist_rs->related_resultset('cds')->count, 0, "No CDs counted on a brand new artist");
31is(scalar($artist_rs->related_resultset('cds')->all), 0, "No CDs fetched on a brand new artist (count == fetch)");
1ec6e7c2 32