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