[Catalyst] Looking For Better Way To Handle SQL LEFT JOIN Situation

hkclark at gmail.com hkclark at gmail.com
Sat Mar 11 02:22:50 CET 2006


I have an application I'm working on where I need to show a table/list
of items along with a count of "child records" for each row in the
table.  It would be very similar to adding a new "Application Count"
column to the "server list" page of Andy Grundman's excellent ServerDB
Catalyst example app.  Using this as an example, I obviously don't
want to do something that will re-query the database once for each
server record just to count the applications.  The only way I have
been able to get it to work is drop back to plain old
"Catalyst-Model-DBI" for my model and use an SQL select like:

SELECT s.name, s.ip_address, s.country, s.state, s.owner, count(a.id)
AS appcount FROM server s LEFT JOIN application a ON s.name = a.server
GROUP BY s.name;

That allows me hit the database a single time and get everything I
need, but as soon as I do that I lose the cool
"Class::DBI::Plugin::Pager" feature (and probably a lot of other stuff
I haven't realized yet).

Is there a way to accomplish what what I want using CDBI (or DBIx)? 
Or is there a way to get "automatic paging via a plugin" with
"Catalyst-Model-DBI" (vs. doing it manually by adding my own LIMIT and
OFFSET to the SELECT along with logic to use it)?  Advice and examples
would be greatly appreciated.

Many thanks,
H



More information about the Catalyst mailing list