X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fprefetch%2Fincomplete.t;h=5d4aee56487c38ecfa594326760ad26ca0b0b15a;hb=908aa1bb761ec1da5c061fe9f687598e3f1934bc;hp=000a386a4aedaee43861e40403373add90a1852f;hpb=69ab63d48af1134c7a6b35ae9005b448a0e37d9e;p=dbsrgits%2FDBIx-Class.git diff --git a/t/prefetch/incomplete.t b/t/prefetch/incomplete.t index 000a386..5d4aee5 100644 --- a/t/prefetch/incomplete.t +++ b/t/prefetch/incomplete.t @@ -1,13 +1,11 @@ use strict; -use warnings; +use warnings; use Test::More; use Test::Exception; use lib qw(t/lib); use DBICTest; -plan tests => 9; - my $schema = DBICTest->init_schema(); lives_ok(sub { @@ -15,14 +13,14 @@ lives_ok(sub { # only the requested me.name column 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 / ], }, ); @@ -33,7 +31,6 @@ lives_ok(sub { 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( @@ -52,14 +49,14 @@ lives_ok ( sub { 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) { @@ -102,3 +99,14 @@ lives_ok(sub { is ($cd->artist->name, 'Random Boy Band', 'Artist object has correct name'); }, 'implicit keyless prefetch works'); + +# sane error +throws_ok( + sub { + $schema->resultset('Track')->search({}, { join => { cd => 'artist' }, '+columns' => 'artist.name' } )->next; + }, + 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"', +); + +done_testing;