From: Matt S Trout Date: Fri, 20 Apr 2012 03:59:31 +0000 (+0000) Subject: correctly handle HAVING without GROUP BY X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=269964a627cac2e5dab322dc903096d5e5f18880;p=dbsrgits%2FDBIx-Class-Historic.git correctly handle HAVING without GROUP BY --- diff --git a/lib/DBIx/Class/SQLMaker/Converter.pm b/lib/DBIx/Class/SQLMaker/Converter.pm index 7cca41c..d927c75 100644 --- a/lib/DBIx/Class/SQLMaker/Converter.pm +++ b/lib/DBIx/Class/SQLMaker/Converter.pm @@ -75,8 +75,11 @@ around _source_to_dq => sub { my ($orig, $self) = (shift, shift); my $attrs = $_[4]; # table, fields, where, order, attrs my $start_dq = $self->$orig(@_); - return $start_dq unless $attrs->{group_by}; - my $grouped_dq = $self->_group_by_to_dq($attrs->{group_by}, $start_dq); + # if we have HAVING but no GROUP BY we render an empty DQ_GROUP + # node, which causes DQ to recognise the HAVING as being what it is. + # This ... is kinda bull. But that's how HAVING is specified. + return $start_dq unless $attrs->{group_by} or $attrs->{having}; + my $grouped_dq = $self->_group_by_to_dq($attrs->{group_by}||[], $start_dq); return $grouped_dq unless $attrs->{having}; +{ type => DQ_WHERE,