I have used this bit of code in my model..It's probably not the best way, but it works for me:
function getMostCommented($limit) { $commentsCount = $this->Comment->find ( 'all', array ( 'fields' => array('article_id', 'count(*) as count'), 'conditions' => '1 = 1 GROUP BY article_id', 'order' => 'count DESC', 'recursive' => -1, 'limit' => $limit ) ); $articles = array(); foreach ($commentsCount as $comment) { $articles = array_merge ( $articles, $this->find ( 'all', array ( 'conditions' => array('id' => $comment['Comment'] ['article_id']), 'fields' => array ( 'id', 'title', 'slug' ), 'recursive' => -1 ) ) ); } return $articles; } This would return the top $limit article with most comments. On Dec 24, 2:14 pm, Fahad <faha...@gmail.com> wrote: > hi, > > i am developing a forum application in cakephp. and need to find a > list of 5 popular topics (threads). popularity is based on the number > of Comment each Topic has. > > is it possible to find popular Topics using cake models only? or do I > have to use custom SQL query for this? > > thanks --~--~---------~--~----~------------~-------~--~----~ 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---