[jifty-devel] simple group by
Jesse Vincent
jesse at bestpractical.com
Mon Apr 14 10:15:42 EDT 2008
On Apr 10, 2008, at 7:15 PM, Dobrica Pavlinusic wrote:
> Is it possible to model something like
>
> select count(l),l from organizations group by l order by count desc
>
> using Jifty::Collection ?
>
The best sample I have for this stuff is actually in RT using
DBIx::SearchBuilder.
lib/RT/Report/Tickets.pm
SearchBuilder is very similar to JDBI. (JDBI was forked from
SearchBuilder a year or two back)
> I have something like:
>
> $orgs->group_by( column => 'l' );
> $orgs->order_by( column => 'l', order => 'desc' );
> $orgs->column( column => 'l', function => 'count(l)' );
>
> which is good for count, but I can't get original name. If I do
> something like:
>
> $orgs->column( column => 'count', function => 'count(l)' );
> $orgs->column( column => 'l' );
>
> SQL query examined with
>
> $orgs->build_select_query
>
> Looks fine:
>
> SELECT count(l) AS main_count, main.l AS main_l FROM organizations
> main
> GROUP BY main.l ORDER BY main.l DESC
>
> but I can't access main_count from resulting object (which somehow
> makes
> sense). Is there any way to access count *and* name at time same time?
>
> --
> Dobrica Pavlinusic 2share!2flame dpavlin at rot13.org
> Unix addict. Internet consultant. http://www.rot13.org/~dpavlin
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
Url : http://lists.jifty.org/pipermail/jifty-devel/attachments/20080414/e9b8a241/attachment.pgp
More information about the jifty-devel
mailing list