One of the things about Cake that I'm not so hot about is having to give up (mostly) writing SQL. For some people, that's a feature, I guess.
Anyway, don't fight the framework ;-) Do your find() on Posts, grabbing Comments along with them. When iterating over them in the view, you can simply do a sizeof() on your array. eg. this is your $posts var set in the controller: Array ( [0] => Array ( [Post] => Array ( [id] => 1 [created] => ... ... [Comment] => Array ( [0] => Array ( [id] ... [1] => Array ( [id] ... foreach($posts as $post) { ?> <h3><?= $post['title'] ?></h3> <h5>(<?= sizeof($post['Comment']) ?> comments)</h5> ... If you're using Bindable behavior you can restrict the SELECT to just grabbing the Comment IDs to save some time/memory, etc. Pagination isn't a factor in any of this (though I may have misunderstood your question). On Mon, Feb 25, 2008 at 12:02 AM, Andrew Allen <[EMAIL PROTECTED]> wrote: > > This may be silly since there is a better to do this I'm sure, but is > there a way to count the number of items in a subselect on pagination? > Or is there a way to count the number of items that are linked in a > hasMany relationship. i.e. can you output the number of comments that > are associated with a post in a blog? > > Thank you in advance. > > Sincerely, > ~Andrew Allen > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---