Sarah Berry wrote:
> On 6/26/06, Matt S Trout <[EMAIL PROTECTED]> 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,@cnt,@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'
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.
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/