Commit | Line | Data |
f4e13e13 |
1 | use warnings; |
2 | use strict; |
3 | |
4 | use Test::More; |
52864fbd |
5 | use Test::Deep; |
f4e13e13 |
6 | |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | |
3d3e99db |
10 | my $schema = DBICTest->init_schema( no_populate => 1 ); |
f4e13e13 |
11 | |
12 | $schema->resultset('CD')->create({ |
3d3e99db |
13 | cdid => 0, title => '', year => 0, genreid => 0, single_track => 0, artist => { |
14 | artistid => 0, name => '', rank => 0, charfield => 0, |
15 | }, |
f4e13e13 |
16 | }); |
17 | |
18 | my $orig_debug = $schema->storage->debug; |
19 | |
20 | my $queries = 0; |
21 | $schema->storage->debugcb(sub { $queries++; }); |
22 | $schema->storage->debug(1); |
23 | |
24 | my $cd = $schema->resultset('CD')->search( {}, { prefetch => 'artist' })->next; |
25 | |
52864fbd |
26 | cmp_deeply |
f4e13e13 |
27 | { $cd->get_columns }, |
3d3e99db |
28 | { artist => 0, cdid => 0, genreid => 0, single_track => 0, title => '', year => 0 }, |
f4e13e13 |
29 | 'Expected CD columns present', |
30 | ; |
31 | |
52864fbd |
32 | cmp_deeply |
f4e13e13 |
33 | { $cd->artist->get_columns }, |
3d3e99db |
34 | { artistid => 0, charfield => 0, name => "", rank => 0 }, |
f4e13e13 |
35 | 'Expected Artist columns present', |
36 | ; |
37 | |
38 | is $queries, 1, 'Only one query fired - prefetch worked'; |
39 | |
40 | $schema->storage->debugcb(undef); |
41 | $schema->storage->debug($orig_debug); |
42 | |
43 | done_testing; |