[Dbix-class] select as, count

Sarah Berry berry.sarah at gmail.com
Mon Jun 26 19:55:22 CEST 2006


On 6/26/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
> Sarah Berry wrote:
> > 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.
>
> You never asked DBIC to generate an accessor method for that field name,
> though - hence there's no method on the class. You'll find
>
> $obj->get_column('qcount');
>
> will work fine.
>

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'



More information about the Dbix-class mailing list