[Dbix-class] select as, count

Sarah Berry berry.sarah at gmail.com
Mon Jun 26 19:38:41 CEST 2006


Hi,

I'm having trouble retrieving the columns I think I should have in a
resultset, specifically when using count(*). I've queried the list
archives and the DBIx::Class cookbook, but I can't seem to get this
right.
Here's my 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' ],
        };
        my @ords = {
                order_by        => 'sensorid DESC' ,
                group_by        => 'sensorid'
        };
        my $rs = $schema->resultset('Tblsensorlog')->search(@conds, at cnt, at ords);
        my $choice = $rs->first;
        $c->stash->{st_record} = $choice->qcount;

The last line doesn't work. I get the following message:
Can't locate object method "qcount" via package
"vieDB::Model::SensorLogDB::Tblsensorlog"

I can change "qcount" in that last line to the name of a field in the
table and access that field just fine. But trying any of the fields I
named myself (month, daymonth, qcount) gives me that error.

Any ideas?

thanks,
Sarah



More information about the Dbix-class mailing list