Commit | Line | Data |
b5c8410c |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
5 | use Test::Exception; |
6 | use lib qw(t/lib); |
7 | use DBICTest; |
8 | |
9 | my $schema = DBICTest->init_schema(); |
10 | |
11 | |
12 | my $artist = $schema->resultset("Artist")->create({ name => 'Michael Jackson' }); |
cf320fd7 |
13 | |
b5c8410c |
14 | foreach my $year (1975..1985) { |
15 | $artist->create_related('cds', { year => $year, title => 'Compilation from ' . $year }); |
16 | } |
17 | |
18 | my @cds_80s = $artist->cds_80s; |
19 | |
20 | is(@cds_80s, 6, '6 80s cds found'); |
21 | |
22 | map { ok($_->year < 1990 && $_->year > 1979) } @cds_80s; |
23 | |
24 | |
25 | |
26 | |
27 | my @last_track_ids; |
28 | for my $cd ($schema->resultset('CD')->search ({}, { order_by => 'cdid'})->all) { |
29 | push @last_track_ids, $cd->tracks |
30 | ->search ({}, { order_by => { -desc => 'position'} }) |
31 | ->get_column ('trackid') |
32 | ->next; |
33 | } |
34 | |
35 | my $last_tracks = $schema->resultset('Track')->search ( |
36 | {'next_track.trackid' => undef}, |
37 | { join => 'next_track', order_by => 'me.cd' }, |
38 | ); |
39 | |
40 | is_deeply ( |
41 | [$last_tracks->get_column ('trackid')->all], |
cf320fd7 |
42 | [ grep { $_ } @last_track_ids ], |
b5c8410c |
43 | 'last group-entry via self-join works', |
44 | ); |
45 | |
46 | done_testing; |