[Dbix-class] Group By statistics columns

Matt Whipple matt at mattwhipple.com
Tue Sep 22 18:48:25 GMT 2009


Trevor Phillips wrote:
> 2009/9/21 Андрей Костенко <andrey at kostenko.name>:
>   
>> You can create a view for this query. e.g.
>> CREATE VIEW stats AS SELECT MIN(a), MAX(a), AVG(a) FROM table1;
>>     
>
> I could, but it's not the query I'm having a problem with - it's
> mapping it to columns within the pre-existing DBIx::Class. I'd rather
> not have to create a whole new class simply for this single query
> against my data. I can see the data in the raw object - I just can't
> access it through the normal methods.
>
> Reading the manual, I should be able to get the value via get_column,
> but Catalyst/TT uses the column methods instead.
>
> Hmmm, I *can* use get_column within TT, but that seems to defeat the
> purpose of abstracting data from presentation.
>   
You could leave the accessor abstracted by creating the function within 
the result class.  Along the lines of
sub a_min { return shift->get_column('a_min'); };
> When getting the search results, I can map the rows with
> $_->get_columns(). That seems to be the easiest solution for now.
>
> --
> Trevor Phillips  - http://dortamur.livejournal.com/
> "On nights such as this, evil deeds are done. And good deeds, of
> course. But mostly evil, on the whole."
>       -- (Terry Pratchett, Wyrd Sisters)
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>   




More information about the DBIx-Class mailing list