Most of the code reviewed... Missing ResultSet->populate, ResultSet->find, Row->copy...
[dbsrgits/DBIx-Class-Historic.git] / t / relationship / custom.t
CommitLineData
b5c8410c 1use strict;
2use warnings;
3
4use Test::More;
5use Test::Exception;
6use lib qw(t/lib);
7use DBICTest;
8
9my $schema = DBICTest->init_schema();
10
11
12my $artist = $schema->resultset("Artist")->create({ name => 'Michael Jackson' });
cf320fd7 13
b5c8410c 14foreach my $year (1975..1985) {
15 $artist->create_related('cds', { year => $year, title => 'Compilation from ' . $year });
16}
17
18my @cds_80s = $artist->cds_80s;
19
20is(@cds_80s, 6, '6 80s cds found');
21
22map { ok($_->year < 1990 && $_->year > 1979) } @cds_80s;
23
24
25
26
27my @last_track_ids;
28for 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
35my $last_tracks = $schema->resultset('Track')->search (
36 {'next_track.trackid' => undef},
37 { join => 'next_track', order_by => 'me.cd' },
38);
39
40is_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
46done_testing;