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' }); |
13 | foreach my $year (1975..1985) { |
14 | $artist->create_related('cds', { year => $year, title => 'Compilation from ' . $year }); |
15 | } |
16 | |
17 | my @cds_80s = $artist->cds_80s; |
18 | |
19 | is(@cds_80s, 6, '6 80s cds found'); |
20 | |
21 | map { ok($_->year < 1990 && $_->year > 1979) } @cds_80s; |
22 | |
23 | |
24 | |
25 | |
26 | my @last_track_ids; |
27 | for my $cd ($schema->resultset('CD')->search ({}, { order_by => 'cdid'})->all) { |
28 | push @last_track_ids, $cd->tracks |
29 | ->search ({}, { order_by => { -desc => 'position'} }) |
30 | ->get_column ('trackid') |
31 | ->next; |
32 | } |
33 | |
34 | my $last_tracks = $schema->resultset('Track')->search ( |
35 | {'next_track.trackid' => undef}, |
36 | { join => 'next_track', order_by => 'me.cd' }, |
37 | ); |
38 | |
39 | is_deeply ( |
40 | [$last_tracks->get_column ('trackid')->all], |
41 | \@last_track_ids, |
42 | 'last group-entry via self-join works', |
43 | ); |
44 | |
45 | done_testing; |