Switch most remaining debug-hooks to $dbictest_schema->is_executed_querycount()
[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
49eeb48d 15$schema->is_executed_querycount( sub {
16 my $pref = $schema->resultset ('Artist')
13d06949 17 ->search ({ 'me.artistid' => $artist->id }, { prefetch => { cds => 'genre' } })
18 ->next;
19
49eeb48d 20 is ($pref->cds->count, 3, 'Correct number of CDs prefetched');
21 is ($pref->cds->search_related ('genre')->count, 1, 'Only one of the prefetched cds has a prefetched genre');
13d06949 22
49eeb48d 23}, 1, 'All happened within one query only');
13d06949 24
13d06949 25done_testing;