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 | |
10 | my $schema = DBICTest->init_schema( |
11 | no_populate => 1, |
12 | ); |
13 | |
14 | $schema->resultset('CD')->create({ |
15 | cdid => 0, |
16 | artist => { |
17 | artistid => 0, |
18 | name => '', |
19 | rank => 0, |
20 | charfield => 0, |
21 | }, |
22 | title => '', |
23 | year => 0, |
24 | genreid => 0, |
25 | single_track => 0, |
26 | }); |
27 | |
28 | my $orig_debug = $schema->storage->debug; |
29 | |
30 | my $queries = 0; |
31 | $schema->storage->debugcb(sub { $queries++; }); |
32 | $schema->storage->debug(1); |
33 | |
34 | my $cd = $schema->resultset('CD')->search( {}, { prefetch => 'artist' })->next; |
35 | |
52864fbd |
36 | cmp_deeply |
f4e13e13 |
37 | { $cd->get_columns }, |
38 | { |
39 | artist => 0, |
40 | cdid => 0, |
41 | genreid => 0, |
42 | single_track => 0, |
43 | title => '', |
44 | year => 0, |
45 | }, |
46 | 'Expected CD columns present', |
47 | ; |
48 | |
52864fbd |
49 | cmp_deeply |
f4e13e13 |
50 | { $cd->artist->get_columns }, |
51 | { |
52 | artistid => 0, |
53 | charfield => 0, |
54 | name => "", |
55 | rank => 0, |
56 | }, |
57 | 'Expected Artist columns present', |
58 | ; |
59 | |
60 | is $queries, 1, 'Only one query fired - prefetch worked'; |
61 | |
62 | $schema->storage->debugcb(undef); |
63 | $schema->storage->debug($orig_debug); |
64 | |
65 | done_testing; |