File: search_related.t

package info (click to toggle)
libdbix-class-perl 0.082844-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,320 kB
  • sloc: perl: 27,215; sql: 322; sh: 29; makefile: 16
file content (41 lines) | stat: -rw-r--r-- 1,199 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use strict;
use warnings;

use Test::More;

use lib qw(t/lib);

use DBICTest;

my $schema = DBICTest->init_schema();
my $cd_rs = $schema->resultset('CD')->search ({}, { rows => 1, order_by => 'cdid' });

my $track_count = $cd_rs->first->tracks->count;

cmp_ok ($track_count, '>', 1, 'First CD has several tracks');

is ($cd_rs->search_related ('tracks')->count, $track_count, 'related->count returns correct number chained off a limited rs');
is (scalar ($cd_rs->search_related ('tracks')->all), $track_count, 'related->all returns correct number of objects chained off a limited rs');


my $joined_cd_rs = $cd_rs->search ({}, {
  join => 'tracks', rows => 2, distinct => 1, having => \ 'count(tracks.trackid) > 2',
});

my $multiple_track_count = $schema->resultset('Track')->search ({
  cd => { -in => $joined_cd_rs->get_column ('cdid')->as_query }
})->count;


is (
  $joined_cd_rs->search_related ('tracks')->count,
  $multiple_track_count,
  'related->count returns correct number chained off a grouped rs',
);
is (
  scalar ($joined_cd_rs->search_related ('tracks')->all),
  $multiple_track_count,
  'related->all returns correct number of objects chained off a grouped rs',
);

done_testing;