[Dbix-class] +as not applied in +select/join/group_by
Jens Gassmann
jens.gassmann at atomix.de
Fri May 29 07:45:02 GMT 2009
Hi Christian,
> To accomplish this, I already tried the following (has_many relationship
> between tables is named 'downloads'):
>
> $rs>search({}, {
> join => 'downloads',
> '+select' => [ { count => 'downloads.id' } ],
> '+as' => [ 'downloadcount' ],
> group_by => 'me.id',
> });
>
> Unfortunately, this only produces this (DBIC_TRACE):
>
> SELECT me.*, COUNT( downloads.id ) FROM publiclinks me
> LEFT JOIN publicdownloads downloads ON downloads.linkid = me.id
> GROUP BY me.id
>
yesterday i build the same - "+as" only defines that you access
"downloadcount" with $object->get_column('downloadcount')
If you like to order by this value, try this, or build the accessor in
the Row-Class.
$rs>search({}, {
join => 'downloads',
'+select' => [ 'COUNT(downloads.id) AS downloadcount' ],
'+as' => [ 'downloadcount' ],
group_by => 'me.id',
order_by => 'downloadcount DESC',
});
<http://search.cpan.org/~ribasushi/DBIx-Class-0.08103/lib/DBIx/Class/ResultSet.pm#+as>
regards,
Jens
More information about the DBIx-Class
mailing list