cds => 'DBICTest::Schema::CD', undef,
{ order_by => { -asc => 'year'} },
);
+
+
+__PACKAGE__->has_many(
+ cds_80s => 'DBICTest::Schema::CD',
+ sub {
+ my ( $rs, $self, $foreign ) = @_;
+ return {
+ "${foreign}.artist" => "${self}.artistid",
+ "${foreign}.year" => { '>', "1979" },
+ "${foreign}.year" => { '<', "1990" }
+ };
+ }
+);
+
+
__PACKAGE__->has_many(
cds_unordered => 'DBICTest::Schema::CD'
);
$cds = $schema->resultset("CD")->search({ 'me.cdid' => 5 }, { join => { single_track => { cd => {} } } });
is($cds->count, 1, "subjoins under left joins force_left (hashref)");
+$artist = $schema->resultset("Artist")->create({ name => 'Michael Jackson' });
+foreach my $year (1975..1985) {
+ $artist->create_related('cds', { year => $year, title => 'Compilation from ' . $year });
+}
+
+my @cds_80s = $artist->cds_80s;
+
+is(@cds_80s, 6, '6 80s cds found');
+
+map { ok($_->year < 1990 && $_->year > 1979) } @cds_80s;
+
done_testing;