The only change you need to make is to add the model name in front of
the star, and to make sure the count syntax results in a usable field
name:

find('all', array('fields' => array('Post.*', '(SELECT COUNT(1) FROM
comments Comment WHERE Comment.post_id = Post.id) AS
comment_count')));

On Feb 3, 5:16 pm, Miles J <mileswjohn...@gmail.com> wrote:
> Ive seen some people do this, but forgot exactly how it should be
> written. Im looking to grab a "total/count" for items within a query.
> For instance, if Im grabbing a list of blog entries, I also want to
> get a total of how many comments each entry has. Instead of doing a
> loop and doing more queries, Ive seen it written within the find it
> self.
>
> find('all', array('fields' => array('*', 'SELECT COUNT(id) AS count
> FROM comments WHERE id = $)));
>
> Is that how you do it?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to