Restore ability to handle underdefined root (t/prefetch/incomplete.t)
[dbsrgits/DBIx-Class.git] / t / prefetch / false_colvalues.t
CommitLineData
f4e13e13 1use warnings;
2use strict;
3
4use Test::More;
5
6use lib qw(t/lib);
7use DBICTest;
8
9my $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
27my $orig_debug = $schema->storage->debug;
28
29my $queries = 0;
30$schema->storage->debugcb(sub { $queries++; });
31$schema->storage->debug(1);
32
33my $cd = $schema->resultset('CD')->search( {}, { prefetch => 'artist' })->next;
34
35is_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
48is_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
59is $queries, 1, 'Only one query fired - prefetch worked';
60
61$schema->storage->debugcb(undef);
62$schema->storage->debug($orig_debug);
63
64done_testing;