Look in the snippets section of symfony. There are examples how to use aggregate functions to get something like "COUNT(*)" done without tons of additional database queries.
Michael On 4 Mai, 11:49, "Gunnar Lium" <[EMAIL PROTECTED]> wrote: > Hi! > > I have an application with a lot of categories, and I want to list the > number of entries for each category. The object oriented way to do this > would be something like: > > foreach ($categories as $category) { > > echo $category->getName() . ' (' . $category->countArticles(). ')'; > > } > > However, this means that I get one extra database-query per category (and > there can be quite a lot of them). > > What's the best practice for solving this? I have considered writing custom > SQL, which would surely work, but at the same time break to OO-paradigm of > symfony, and also considered caching the action (but since the categories > are updated at least every few minutes, this would demand a lot of clearing > of the cache). > > Any suggestions? > > Thanks, > > Gunnar Lium --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---