Stop adding empty caches to resultsets chained off prefetched objects
[dbsrgits/DBIx-Class.git] / t / prefetch / refined_search_on_relation.t
CommitLineData
9ae300a4 1use strict;
2use warnings;
3
4use Test::More;
5use lib qw(t/lib);
6use DBICTest;
7
8my $schema = DBICTest->init_schema();
9
10my $art = $schema->resultset('Artist')->find(
11 { 'me.artistid' => 1 },
12 { prefetch => 'cds', order_by => { -desc => 'cds.year' } }
13);
14
15is (
16 $art->cds->search({ year => 1999 })->next->year,
17 1999,
18 'Found expected CD with year 1999 after refined search',
19);
20
21is (
22 $art->cds->count({ year => 1999 }),
23 1,
24 'Correct refined count',
25);
26
27# this still should emit no queries:
28{
29 my $queries = 0;
30 my $orig_debug = $schema->storage->debug;
31 $schema->storage->debugcb(sub { $queries++; });
32 $schema->storage->debug(1);
33
34 my $cds = $art->cds;
35 is (
36 $cds->count,
37 3,
38 'Correct prefetched count',
39 );
40
41 my @years = qw(2001 1999 1997);
42 while (my $cd = $cds->next) {
43 is (
44 $cd->year,
45 (shift @years),
46 'Correct prefetched cd year',
47 );
48 }
49
50 $schema->storage->debug($orig_debug);
51 $schema->storage->debugcb(undef);
52
53 is ($queries, 0, 'No queries on prefetched operations');
54}
55
56done_testing;