[Dbix-class] select as, count

Sarah Berry berry.sarah at gmail.com
Mon Jun 26 20:28:19 CEST 2006


> >
> > No luck ... I changed the last line to
> >         $c->stash->{st_record} = $choice->get_column('qcount');
> > and got the error
> >         "DBIx::Class::Row::get_column(): No such column 'qcount'
>
> Hang on, your search syntax is completely wrong. You need to pass it a single
> \%attrs hashref, currently you're trying to pass two ($cnt[0] and $ords[0]) so
> it only sees the second one.
>

Thanks, that was it!

The working code:

        my @conds = {
                date            => { '>' => '2006-06-21 11:59:59', '<'
=> '2006-06-22 11:59:59' },                sensorid        => { '>' =>
'4', '<' => '9' },
        };
        my @cnt = {
                select  => [ "DATE_FORMAT(date,'%b')",
'DAYOFMONTH(date)', { count => '*' } ],
                as      => [ 'month', 'daymonth', 'qcount' ],
                order_by        => [ 'sensorid DESC' ] ,
                group_by        => [ 'sensorid' ]
        };
        my $rs = $schema->resultset('Tblsensorlog')->search(@conds, at cnt);
        my $choice = $rs->first;
        $c->stash->{st_record} = $choice->get_column('month');



More information about the Dbix-class mailing list