Extra authordeps
[dbsrgits/DBIx-Class.git] / t / count / search_related.t
CommitLineData
5978a0e8 1use strict;
2use warnings;
3
4use Test::More;
5
6use lib qw(t/lib);
7
8use DBICTest;
9
10my $schema = DBICTest->init_schema();
11my $cd_rs = $schema->resultset('CD')->search ({}, { rows => 1, order_by => 'cdid' });
12
13my $track_count = $cd_rs->first->tracks->count;
14
15cmp_ok ($track_count, '>', 1, 'First CD has several tracks');
16
533b7dba 17is ($cd_rs->search_related ('tracks')->count, $track_count, 'related->count returns correct number chained off a limited rs');
18is (scalar ($cd_rs->search_related ('tracks')->all), $track_count, 'related->all returns correct number of objects chained off a limited rs');
19
20
21my $joined_cd_rs = $cd_rs->search ({}, {
22 join => 'tracks', rows => 2, distinct => 1, having => \ 'count(tracks.trackid) > 2',
23});
24
25my $multiple_track_count = $schema->resultset('Track')->search ({
26 cd => { -in => $joined_cd_rs->get_column ('cdid')->as_query }
27})->count;
28
29
30is (
31 $joined_cd_rs->search_related ('tracks')->count,
32 $multiple_track_count,
33 'related->count returns correct number chained off a grouped rs',
34);
35is (
36 scalar ($joined_cd_rs->search_related ('tracks')->all),
37 $multiple_track_count,
38 'related->all returns correct number of objects chained off a grouped rs',
39);
5978a0e8 40
41done_testing;