lives_ok(sub {
# while cds.* will be selected anyway (prefetch currently forces the result of _resolve_prefetch)
- # only the requested me.name column will be fetched.
+ # only the requested me.name/me.artistid columns will be fetched.
# reference sql with select => [...]
- # SELECT me.name, cds.title, cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track FROM ...
+ # SELECT me.name, cds.title, me.artistid, cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track FROM ...
my $rs = $schema->resultset('Artist')->search(
{ 'cds.title' => { '!=', 'Generic Manufactured Singles' } },
{
prefetch => [ qw/ cds / ],
order_by => [ { -desc => 'me.name' }, 'cds.title' ],
- select => [qw/ me.name cds.title / ],
+ select => [qw/ me.name cds.title me.artistid / ],
},
);
is ($we_are_goth->cds->first->title, 'Come Be Depressed With Us', 'Correct cd for artist');
}, 'explicit prefetch on a keyless object works');
-
lives_ok ( sub {
my $rs = $schema->resultset('CD')->search(
my @cds_and_tracks;
for my $cd ($rs->all) {
- my $data->{year} = $cd->year;
+ my $data = { year => $cd->year, cdid => $cd->cdid };
for my $tr ($cd->tracks->all) {
push @{$data->{tracks}}, { $tr->get_columns };
}
push @cds_and_tracks, $data;
}
- my $pref_rs = $rs->search ({}, { columns => ['year'], prefetch => 'tracks' });
+ my $pref_rs = $rs->search ({}, { columns => [qw/year cdid/], prefetch => 'tracks' });
my @pref_cds_and_tracks;
for my $cd ($pref_rs->all) {
sub {
$schema->resultset('Track')->search({}, { join => { cd => 'artist' }, '+columns' => 'artist.name' } )->next;
},
- qr|\QCan't inflate manual prefetch into non-existent relationship 'artist' from 'Track', check the inflation specification (columns/as) ending in 'artist.name'|,
+ qr|\QCan't inflate prefetch into non-existent relationship 'artist' from 'Track', check the inflation specification (columns/as) ending in '...artist.name'|,
'Sensible error message on mis-specified "as"',
);
+# check complex limiting prefetch without the join-able columns
+{
+ my $pref_rs = $schema->resultset('Owners')->search({}, {
+ rows => 3,
+ offset => 1,
+ columns => 'name', # only the owner name, still prefetch all the books
+ prefetch => 'books',
+ });
+
+ lives_ok {
+ is ($pref_rs->all, 1, 'Expected count of objects on limtied prefetch')
+ } "Complex limited prefetch works with non-selected join condition";
+}
+
+
done_testing;