Friday, June 25, 2010

Re: controllers index function with related tables.

On Fri, Jun 25, 2010 at 12:47 PM, Jeremy Burns | Class Outfit
<jeremyburns@classoutfit.com> wrote:
>
> To get the count of comments you can either do a
> count of comments from within the array, or use the counterCache function.

If you don't go with counterCache you might want to adjust the
contains array so that you're only fetching the ID for each comment.

$posts = $this->Post->find(
'all',
array(
'contain' => array(
'Comment' => array(
'fields' => array(
'Comment.id'
)
),
'Tag'
)
)
);

This way, you're not fetching a bunch of unnecessary data and you can
use sizeof() to get the number of comments for each post.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: