use lib qw(t/lib);
use DBICTest;
-plan tests => 7;
-
my $schema = DBICTest->init_schema();
my $no_prefetch = $schema->resultset('Artist')->search(
- undef,
- { rows => 3 }
-);
-
-my $use_prefetch = $schema->resultset('Artist')->search(
[ # search deliberately contrived
{ 'artwork.cd_id' => undef },
{ 'tracks.title' => { '!=' => 'blah-blah-1234568' }}
],
+ { rows => 3, join => { cds => [qw/artwork tracks/] },
+ }
+);
+
+my $use_prefetch = $no_prefetch->search(
+ {},
{
+ select => ['me.artistid', 'me.name'],
+ as => ['artistid', 'name'],
prefetch => 'cds',
- join => { cds => [qw/artwork tracks/] },
- rows => 3,
order_by => { -desc => 'name' },
}
);
qr/resultsets prefetching has_many/,
'single() with multiprefetch is illegal',
);
+
+my $artist = $use_prefetch->search({'cds.title' => $artist_many_cds->cds->first->title })->next;
+is($artist->cds->count, 1, "count on search limiting prefetched has_many");
+
+# try with double limit
+my $artist2 = $use_prefetch->search({'cds.title' => { '!=' => $artist_many_cds->cds->first->title } })->slice (0,0)->next;
+is($artist2->cds->count, 2, "count on search limiting prefetched has_many");
+
+done_testing;