Hi
I'm new to CakePHP and maybe it's a very stupid question. But I don't
hope so :)
My question is: How to use a group by clause with paginate()? Here's a
short description of my project:
Table 'news':
Id, title, ...
Table 'comments':
Id, news_id, ...
I want to query all news with the number of comments, which are
related to this news-entry.
After baking I got the following code:
function index() {
$this->News->recursive = 0;
$this->set('news', $this->paginate('News'));
}
After reading the API (http://api.cakephp.org/class/controller#method-
Controllerpaginate) I think, that I have to do this with some
additional constructions.
I thought of querying all number of comments with the related news-id:
SELECT news_id, count( * ) AS counter
FROM comments
GROUP BY news_id
This results in an easy-to-use table, which could be placed in an
array. Then I could access the count with the news_id as a key.
Is this a good idea in the world of CakePHP and how can I realize it?
Thanks a lot
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---