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