So you want to see the count of posts for each country and the country
data is stored in the Profile?
My instinct tells me you have the structure you need and that a single
$this->Post->find('all', array('your params here')) is going to return
the result you want once you dial in all the find parameters. I'm not
good at writing these find()s off the top of my head so I can't bang
out a working example for you. It's all here though :-)
http://book.cakephp.org/view/1018/find
You should check into the Containable behavior though (http://
book.cakephp.org/view/1323/Containable). That give's a nice clean way
to cherry-pick your fields in a deep nest of returned data.
The only stumbling block I can see is 'count'. I remember seeing a
little discussion on how to do that but I can't pop out a reference
for you right now.
Regards,
Don
On May 12, 10:31 am, amiable_indian <[email protected]> wrote:
> Thanks! What you said works, but I was trying to avoid all those individual
> queries (which would be equal to number of posts in this case) and generate
> a single query like this...
>
> SELECT Profile.country_code, COUNT(Post.id) as `post_count`
> FROM
> Post
> JOIN Profile ON ( Post.user_id = Profile.user_id )
> WHERE
> Profile.country_code IS NOT NULL
> GROUP BY
> Profile.country_code
>
> Hope it makes sense this time around :)
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php