[Kc] DBIx::Class::ResultSet / Template Toolkit / Aggregate Group By

Jonathan Otsuka djgoku at gmail.com
Wed Jun 10 12:09:32 PDT 2009


On Jun 10, 2009, at 1:39 PM, Stephen Clouse wrote:

> On Wed, Jun 10, 2009 at 12:15 PM, Jonathan Otsuka <djgoku at gmail.com>  
> wrote:
>  $c->stash->{stuff} = [
>         $c->model('DB::Blah')->search(
>             {},
>             { select => ['data', { count => 'data' }], group_by =>  
> ['data '] }
>         )
>     ];
>
> You want the "as" attribute on your query:
>
> $c->model('DB::Blah')->search(
>     {},
>     { select   => [ 'data', { count => 'data' } ],
>       as       => [ 'data', 'cnt' ],
>       group_by => [ 'data' ],
>     },
> );
>
> And then:
>
> $rec->data;
> $rec->get_column('cnt');
>
> Note the necessity of using get_column here, since "cnt" is not an  
> actual table column and thus won't have an auto-generated accessor  
> method.

Hooray!!! Thank  you! I didn't think of using an alias!

Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/kc/attachments/20090610/30bce30a/attachment.html>


More information about the kc mailing list