display properly in DBIC_TRACE
- Incomplete exception thrown on relationship auto-fk-inference
failures
+ - Fixed distinct with order_by to not double-specify the same
+ column in the GROUP BY clause
* Misc
- Makefile.PL no longer imports GetOptions() to interoperate
carp ("Useless use of distinct on a grouped resultset ('distinct' is ignored when a 'group_by' is present)");
}
else {
- $attrs->{group_by} = [ grep { !ref($_) || (ref($_) ne 'HASH') } @{$attrs->{select}} ];
+ my $storage = $self->result_source->schema->storage;
+ my $rs_column_list = $storage->_resolve_column_info ($attrs->{from});
+
+ my $group_spec = $attrs->{group_by} = [];
+ my %group_index;
+ for (@{$attrs->{select}}) {
+ if (! ref($_) or ref ($_) ne 'HASH' ) {
+ push @$group_spec, $_;
+ $group_index{$_}++;
+ if ($rs_column_list->{$_} and $_ !~ /\./ ) {
+ # add a fully qualified version as well
+ $group_index{"$rs_column_list->{$_}{-source_alias}.$_"}++;
+ }
+ }
+ }
# add any order_by parts that are not already present in the group_by
# we need to be careful not to add any named functions/aggregates
# i.e. select => [ ... { count => 'foo', -as 'foocount' } ... ]
- my %already_grouped = map { $_ => 1 } (@{$attrs->{group_by}});
-
- my $storage = $self->result_source->schema->storage;
+ for my $chunk ($storage->_parse_order_by($attrs->{order_by})) {
- my $rs_column_list = $storage->_resolve_column_info ($attrs->{from});
+ # only consider real columns (for functions the user got to do an explicit group_by)
+ my $colinfo = $rs_column_list->{$chunk}
+ or next;
- for my $chunk ($storage->_parse_order_by($attrs->{order_by})) {
- if ($rs_column_list->{$chunk} && not $already_grouped{$chunk}++) {
- push @{$attrs->{group_by}}, $chunk;
- }
+ $chunk = "$colinfo->{-source_alias}.$chunk" if $chunk !~ /\./;
+ push @$group_spec, $chunk unless $group_index{$chunk}++;
}
}
}
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, cdid
+ 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