Back out constructor/prefetch rewrite introduced mainly by 43245ada4a
[dbsrgits/DBIx-Class.git] / t / prefetch / one_to_many_to_one.t
CommitLineData
13d06949 1use strict;
2use warnings;
3
4use Test::More;
13d06949 5
6use lib qw(t/lib);
7use DBICTest;
8
9my $schema = DBICTest->init_schema();
10
11my $artist = $schema->resultset ('Artist')->find ({artistid => 1});
12is ($artist->cds->count, 3, 'Correct number of CDs');
13is ($artist->cds->search_related ('genre')->count, 1, 'Only one of the cds has a genre');
14
15my $queries = 0;
16my $orig_cb = $schema->storage->debugcb;
17$schema->storage->debugcb(sub { $queries++ });
18$schema->storage->debug(1);
19
c9733800 20
13d06949 21my $pref = $schema->resultset ('Artist')
22 ->search ({ 'me.artistid' => $artist->id }, { prefetch => { cds => 'genre' } })
23 ->next;
24
25is ($pref->cds->count, 3, 'Correct number of CDs prefetched');
26is ($pref->cds->search_related ('genre')->count, 1, 'Only one of the prefetched cds has a prefetched genre');
27
c9733800 28
13d06949 29is ($queries, 1, 'All happened within one query only');
30$schema->storage->debugcb($orig_cb);
31$schema->storage->debug(0);
32
c9733800 33
13d06949 34done_testing;