Hi, many thanks for the adivce, i agree with your opinion, but like you say none of the solutions are the better way for now i used another solution (new field on posts table for counting the comments) it breaks some modelling rules but for now solves the problem easly
regards Paulo On Aug 19, 11:40 pm, MonkeyGirl <[EMAIL PROTECTED]> wrote: > Hi. > > I don't necessarily know what I'm talking about, but no one else has > spoken up, so here goes... > > The way I would get the aggregate would not be to change the > finderQuery in the hasAndBelongsToMany definition. It didn't even > occur to me that you could do that. Then again, maybe I'm just being > naive. Either of these ways should work: > > The wasteful way: just do a findAll on the tag and recurse it as > necessary. It will list all the posts that use it, and all the > comments that each post has. Use PHP's count() function rather than > SQL aggregates to count how many comments are in each post. As I say, > this is very much needlessly wasteful, although you can curb the waste > somewhat by unbinding the unneeded models temporarily before the > findAll. > > The custom way: make a new method in one of the models that takes a > tag ID and calls $this->query with the SQL you've pasted above, and a > WHERE clause that makes use of the tag ID. This is probably the best > way of doing it (it's certainly the best way I know of myself), but > I'll bet someone else can suggest a better way. > > But as I say, I'm by no means an expert, so take my advice with a > pinch of salt. > > Hope that helps, > Zoe. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
