Timm wrote:
> Thanks for your advice. I have already played with associations, but I
> could not figure out, how I can get the number of comments associated
> with each post. (see the query I presented in the initial post
The query you present is quite simple and doesn't really need any
bespoke SQL.

I think this would do it:
//In your Post Model
class Post extends AppModel
{
        var $name = 'Post';
        var $hasMany = 'Comment';
..

//In controller
$data = $this->Post->findAll();
foreach ($data as $Blog)
{
$NumberOfComments = isset ($data['Comment'])?count($data['Comment']):0;
...

If you do need to do a custom query, use "query"
http://api.cakephp.org/class_model.html#0014cb0f3c55887178b62ce53dbc4733

It's a shame the wiki search isn't working too well, but you'll
probably find the cake search tool useful for such questions
(http://www.cakephp.org/search/index/query)

Cheers,

AD7six


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to