[Dbix-class] Selecting max() of count()
BUNK (Jacob Bunk Nielsen)
bunk at novozymes.com
Fri Aug 1 11:06:06 BST 2008
Iain Hubbard <iain.hubbard at gmgrd.co.uk> writes:
> On Wed, 2008-07-30 at 14:55 +0200, BUNK (Jacob Bunk Nielsen) wrote:
>> $baskets->search({ },
>> { select => [ { count => 'item_id' }, ],
>> as => [ 'no_of_items' ],
>> group_by => [ 'basket_id' ],
>> })->get_column('no_of_items')->max;
>>
>> Unfortunately this doesn't cut it. It ends up complaining that there is
>> no column called 'no_of_items' for the query:
>>
>> SELECT MAX( "no_of_items" )
>> FROM "shop"."basket" "me"
>> WHERE ( ( ( "basket_id" = ? ) OR ( "basket_id" = ? ) ) )
>> GROUP BY "basket_id"" with ParamValues: 1='1', 2='2'
>>
>> It totally ignores my part about 'select count(item_id) as no_of_items'.
>>
>> How do I make dbix-class make the right database query?
>
> I think its the as => [ 'no_of_items' ] not doing what you think.
Perhaps, but it also ignores any mentioning of 'count'. This doesn't
seem logical to me. Do you have any idea why it ignores count?
Best regards
Jacob
More information about the DBIx-Class
mailing list