I didn't try this but you can give it a try. Put count(post_id) as a
field name. I'm 90% sure that this won't work (when using aggregation
functions in the query, SQL requires that every other non-aggregation
field you select to be present in group by clause). But still you can
try it anyway.
On 10 Lis, 17:38, Action <[EMAIL PROTECTED]> wrote:
> I currently have it so the association just pulls in the post_id for
> each comment then I just count() that array in the view for the
> comment count:
>
> $this->Post->bindModel(array('hasMany' => array('Comment' =>
> array('fields' => array('post_id')))));
> $this->set('data', $this->Post->find('all', array('order' =>
> 'created DESC')));
>
> Is there a better way to do this?
>
> On Nov 10, 1:57 am, francky06l <[EMAIL PROTECTED]> wrote:
>
> > You bind your model again, using 'fields' option to set the fields you
> > want :
>
> > $this->Post->bindModel(array('hasMany' => array('Comment' =>
> > array('className' => 'Comment',
> > 'fields' => array('field you
> > want'))));
>
> > On Nov 10, 4:55 am, Action <[EMAIL PROTECTED]> wrote:
>
> > > I want to be able to retrieve multiple blog posts as well as the
> > > comment count for each post. I do not want to retrieve the comments
> > > themselves, just the comment count.
>
> > > This is what I have so far:
>
> > > $this->Post->unbindModel(array('hasMany' => array('Comment')));
>
> > > $this->set('data', $this->Post->find('all', array('order' => 'created
> > > DESC')));
>
> > > I unbound the model association so it wouldn't pull the comments in
> > > the query. How can I make it so the find() as also grabs the comment
> > > count for each post it is grabbing?
>
> > > If I kept the association it would work, but I would have to also pull
> > > all of the comment data as well, which is something I don't want to
> > > do.
>
> > > Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---