X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fprefetch%2Fmanual.t;h=72bde38af49b80b8d61c02404394dd546d30fa3d;hb=908aa1bb761ec1da5c061fe9f687598e3f1934bc;hp=75b117e365a0872702db456ca037424875588749;hpb=69ab63d48af1134c7a6b35ae9005b448a0e37d9e;p=dbsrgits%2FDBIx-Class.git diff --git a/t/prefetch/manual.t b/t/prefetch/manual.t index 75b117e..72bde38 100644 --- a/t/prefetch/manual.t +++ b/t/prefetch/manual.t @@ -6,7 +6,45 @@ use Test::Exception; use lib qw(t/lib); use DBICTest; -my $schema = DBICTest->init_schema(); +my $schema = DBICTest->init_schema(no_populate => 1); + +$schema->resultset('CD')->create({ + title => 'Equinoxe', + year => 1978, + artist => { name => 'JMJ' }, + genre => { name => 'electro' }, + tracks => [ + { title => 'e1' }, + { title => 'e2' }, + { title => 'e3' }, + ], + single_track => { + title => 'o1', + cd => { + title => 'Oxygene', + year => 1976, + artist => { + name => 'JMJ', + cds => [ + { + title => 'Magnetic Fields', + year => 1981, + genre => { name => 'electro' }, + tracks => [ + { title => 'm1' }, + { title => 'm2' }, + { title => 'm3' }, + { title => 'm4' }, + ], + }, + ], + }, + tracks => [ + { title => 'o2', position => 2}, # the position should not be here, bug in MC + ], + }, + }, +}); my $rs = $schema->resultset ('CD')->search ({}, { join => [ 'tracks', { single_track => { cd => { artist => { cds => 'tracks' } } } } ], @@ -16,16 +54,153 @@ my $rs = $schema->resultset ('CD')->search ({}, { { 'genreid' => 'me.genreid' }, # nullable { 'tracks.title' => 'tracks.title' }, # non-unique (no me.id) { 'single_track.cd.artist.cds.cdid' => 'cds.cdid' }, # to give uniquiness to ...tracks.title below - { 'single_track.cd.artist.cds.artist' => 'cds.artist' }, # non-unique + { 'single_track.cd.artist.artistid' => 'artist.artistid' }, # uniqufies entire parental chain { 'single_track.cd.artist.cds.year' => 'cds.year' }, # non-unique { 'single_track.cd.artist.cds.genreid' => 'cds.genreid' }, # nullable { 'single_track.cd.artist.cds.tracks.title' => 'tracks_2.title' }, # unique when combined with ...cds.cdid above - { 'latest_cd' => { max => 'cds.year' } }, # random function + { 'latest_cd' => \ "(SELECT MAX(year) FROM cd)" }, # random function + { 'title' => 'me.title' }, # uniquiness for me + { 'artist' => 'me.artist' }, # uniquiness for me ], - result_class => 'DBIx::Class::ResultClass::HashRefInflator', + order_by => [{ -desc => 'cds.year' }, { -desc => 'me.title'} ], }); -use Data::Dumper::Concise; -die Dumper [$rs->all]; +my $hri_rs = $rs->search({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }); + +is_deeply ( + [$hri_rs->all], + [ + { + artist => 1, + genreid => 1, + latest_cd => 1981, + single_track => { + cd => { + artist => { + artistid => 1, + cds => [ + { + cdid => 1, + genreid => 1, + tracks => [ + { + title => "m1" + }, + { + title => "m2" + }, + { + title => "m3" + }, + { + title => "m4" + } + ], + year => 1981 + }, + { + cdid => 3, + genreid => 1, + tracks => [ + { + title => "e1" + }, + { + title => "e2" + }, + { + title => "e3" + } + ], + year => 1978 + }, + { + cdid => 2, + genreid => undef, + tracks => [ + { + title => "o1" + }, + { + title => "o2" + } + ], + year => 1976 + } + ] + } + } + }, + title => "Equinoxe", + tracks => [ + { + title => "e1" + }, + { + title => "e2" + }, + { + title => "e3" + } + ], + year => 1978 + }, + { + artist => 1, + genreid => undef, + latest_cd => 1981, + single_track => undef, + title => "Oxygene", + tracks => [ + { + title => "o1" + }, + { + title => "o2" + } + ], + year => 1976 + }, + { + artist => 1, + genreid => 1, + latest_cd => 1981, + single_track => undef, + title => "Magnetic Fields", + tracks => [ + { + title => "m1" + }, + { + title => "m2" + }, + { + title => "m3" + }, + { + title => "m4" + } + ], + year => 1981 + }, + ], + 'W00T, manual prefetch with collapse works' +); + +my $row = $rs->next; + +TODO: { + local $TODO = 'Something is wrong with filter type rels, they throw on incomplete objects >.<'; + + lives_ok { + is_deeply ( + { $row->single_track->get_columns }, + {}, + 'empty intermediate object ok', + ) + } 'no exception'; +} +is ($rs->cursor->next, undef, 'cursor exhausted'); +done_testing;