From: Eden Cardim Date: Tue, 10 Nov 2009 19:21:38 +0000 (+0000) Subject: added test case for ensuring a column mentioned in the order by clause is also includ... X-Git-Tag: v0.08116~138^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d59eba65f;p=dbsrgits%2FDBIx-Class.git added test case for ensuring a column mentioned in the order by clause is also included in the group by clause --- diff --git a/t/prefetch/grouped.t b/t/prefetch/grouped.t index 7f97943..f6fabae 100644 --- a/t/prefetch/grouped.t +++ b/t/prefetch/grouped.t @@ -217,7 +217,7 @@ for ($cd_rs->all) { $rs->as_query, '( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, - tags.tagid, tags.cd, tags.tag + tags.tagid, tags.cd, tags.tag FROM ( SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me @@ -329,4 +329,27 @@ for ($cd_rs->all) { ); } +{ + my $rs = $schema->resultset('CD')->search({}, + { + '+select' => [{ count => 'tags.tag' }], + '+as' => ['test_count'], + prefetch => ['tags'], + distinct => 1, + order_by => {'-asc' => 'tags.tag'}, + rows => 1 + } + ); + is_same_sql_bind($rs->as_query, q{ + SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, me.test_count, tags.tagid, tags.cd, tags.tag + FROM (SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, COUNT( tags.tag ) AS test_count + FROM cd me LEFT JOIN tags tags ON tags.cd = me.cdid + GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, tags.tag + ORDER BY tags.tag ASC LIMIT 1) + me + LEFT JOIN tags tags ON tags.cd = me.cdid + ORDER BY tags.tag ASC, tags.cd, tags.tag + }, []); +} + done_testing;