CC: | Tony WCN <tony.langdon [...] wcn.co.uk> |
Subject: | Issue with alias names in +as with group by - 0.082810 |
Date: | Thu, 29 Oct 2015 18:05:32 +0000 |
To: | bug-DBIx-Class [...] rt.cpan.org |
From: | Tony Langdon <tony.langdon [...] wcn.co.uk> |
I have attached minimal code to reproduce the issue.
I think part of the problem is in DBIx::Class::Storage::DBI in _select_args line 2481
$prefetch_needs_subquery = ! scalar grep { $_ ne $attrs->{alias} } keys %{ $grp_aliases->{grouping} || {} };
I think that the ! is wrong since the subquery would only be needed if there are grouping aliases that aren’t that of this table.
That’s what I was trying to reproduce with the attached code (using Artist / CDs) but I also discovered that the aggregate column is not available in the result row when including the aggregate column.
e.g.
This is OK (with the_wall_cds being a custom relationship to cds)
my $spec = { '+as' => [ 'name', 'number' ],
'+select' => [ 'me.name', 'count(the_wall_cds.cdid)' ],
'columns' => [],
'join' => 'the_wall_cds',
'group_by' => ['me.name'], };
my $rs = $artist_rs->search_rs( {}, $spec );
However this is not:
my $spec = { '+as' => [ 'name', 'the_wall_cds.number' ],
'+select' => [ 'me.name', 'count(the_wall_cds.cdid)' ],
'columns' => [],
'join' => 'the_wall_cds',
'group_by' => ['me.name'], };
my $rs = $artist_rs->search_rs( {}, $spec );
Attached code should be self contained illustration of the issue.
We’re trying to update our application to a more recent version of DBIx::Class (from 0.08196) and this is changed behaviour,
Thanks.
I have attached minimal code to reproduce the issue.
I think part of the problem is in DBIx::Class::Storage::DBI in _select_args line 2481
$prefetch_needs_subquery = ! scalar grep { $_ ne $attrs->{alias} } keys %{ $grp_aliases->{grouping} || {} };
I think that the ! is wrong since the subquery would only be needed if there are grouping aliases that aren’t that of this table.
That’s what I was trying to reproduce with the attached code (using Artist / CDs) but I also discovered that the aggregate column is not available in the result row when including the aggregate column.
e.g.
This is OK (with the_wall_cds being a custom relationship to cds)
Show quoted textmy $spec = { '+as' => [ 'name', 'number' ],'+select' => [ 'me.name', 'count(the_wall_cds.cdid)' ],'columns' => [],'join' => 'the_wall_cds','group_by' => ['me.name'], };my $rs = $artist_rs->search_rs( {}, $spec );
However this is not:
Show quoted textmy $spec = { '+as' => [ 'name', 'the_wall_cds.number' ],'+select' => [ 'me.name', 'count(the_wall_cds.cdid)' ],'columns' => [],'join' => 'the_wall_cds','group_by' => ['me.name'], };my $rs = $artist_rs->search_rs( {}, $spec );
Attached code should be self contained illustration of the issue.
We’re trying to update our application to a more recent version of DBIx::Class (from 0.08196) and this is changed behaviour,
Thanks.
Message body not shown because it is not plain text.