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