-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate caches for related result sets even if they're empty
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
use lib qw(t/lib); | ||
use DBICTest; | ||
|
||
my $schema = DBICTest->init_schema(); | ||
|
||
my $queries; | ||
my $debugcb = sub { $queries++; }; | ||
my $orig_debug = $schema->storage->debug; | ||
|
||
{ | ||
$queries = 0; | ||
$schema->storage->debugcb($debugcb); | ||
$schema->storage->debug(1); | ||
|
||
my $cds_rs = $schema->resultset('CD') | ||
->search(\'0 = 1', { prefetch => 'tracks', cache => 1 }); | ||
|
||
my @cds = $cds_rs->all; | ||
is( $queries, 1, '->all on empty original resultset hit db' ); | ||
is_deeply( $cds_rs->get_cache, [], 'empty cache on original resultset' ); | ||
is( 0+@cds, 0, 'empty original resultset' ); | ||
|
||
my $tracks_rs = $cds_rs->related_resultset('tracks'); | ||
is_deeply( $tracks_rs->get_cache, [], 'empty cache on related resultset' ); | ||
|
||
my @tracks = $tracks_rs->all; | ||
is( $queries, 1, "->all on empty related resultset didn't hit db" ); | ||
is( 0+@tracks, 0, 'empty related resultset' ); | ||
|
||
$schema->storage->debugcb(undef); | ||
$schema->storage->debug($orig_debug); | ||
} | ||
|
||
done_testing; |