X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fprefetch%2Fgrouped.t;h=92f383cfd988676b1d0232c0eb3db112655cca3e;hb=086901c30dcd1c87b678c44bfd1d42ace0b5e18f;hp=0a61f976d91c2f5b8d7a5de8d232e287c48b7b1b;hpb=8ab3290b4c6bdb3c9c84172afca234169184ff06;p=dbsrgits%2FDBIx-Class.git diff --git a/t/prefetch/grouped.t b/t/prefetch/grouped.t index 0a61f97..92f383c 100644 --- a/t/prefetch/grouped.t +++ b/t/prefetch/grouped.t @@ -1,14 +1,13 @@ use strict; use warnings; + use Test::More; +use Test::Exception; use lib qw(t/lib); use DBICTest; use DBIC::SqlMakerTest; -#plan tests => 6; -plan 'no_plan'; - my $schema = DBICTest->init_schema(); my $sdebug = $schema->storage->debug; @@ -205,3 +204,35 @@ for ($cd_rs->all) { $schema->storage->debugcb (undef); $schema->storage->debug ($sdebug); } + +# make sure that distinct still works +{ + my $rs = $schema->resultset("CD")->search({}, { + prefetch => 'tags', + order_by => 'cdid', + distinct => 1, + }); + + is_same_sql_bind ( + $rs->as_query, + '( + SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, + tags.tagid, tags.cd, tags.tag + FROM ( + SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track + FROM cd me + GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track + ORDER BY cdid + ) me + LEFT JOIN tags tags ON tags.cd = me.cdid + ORDER BY cdid, tags.cd, tags.tag + )', + [], + 'Prefetch + distinct resulted in correct group_by', + ); + + is ($rs->all, 5, 'Correct number of CD objects'); + is ($rs->count, 5, 'Correct count of CDs'); +} + +done_testing;