From: Michael Reddick Date: Fri, 19 Nov 2010 00:25:14 +0000 (-0600) Subject: added test for count on rs with having a clause that uses a sql as alias X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fghpr%2Fclosed%2Finspiring_e493ecb2;p=dbsrgits%2FDBIx-Class-Historic.git added test for count on rs with having a clause that uses a sql as alias --- diff --git a/t/count/count_rs.t b/t/count/count_rs.t index f947a9b..2606529 100644 --- a/t/count/count_rs.t +++ b/t/count/count_rs.t @@ -115,3 +115,34 @@ my $schema = DBICTest->init_schema(); 'count_rs db-side limit applied', ); } + +# count with a having clause +{ + my $rs = $schema->resultset("Artist")->search( + {}, + { + join => 'cds', + group_by => 'me.artistid', + '+select' => [ { 'max' => \'cds.year', -as => 'newest_cd_year' } ], + '+as' => ['newest_cd_year'], + having => { 'newest_cd_year' => '2001' } + } + ); + my $crs = $rs->count_rs; + + is_same_sql_bind ( + $crs->as_query, + '(SELECT COUNT( * ) + FROM ( + SELECT me.artistid, MAX( cds.year ) AS newest_cd_year + FROM artist me + LEFT JOIN cd cds ON cds.artist = me.artistid + GROUP BY me.artistid + HAVING newest_cd_year = ? + ) me + )', + [ [ 'newest_cd_year' => '2001' ],], + 'count with having clause keeps sql as alias', + ); + +}