2012-06-12 47 views
0

計數場訂購SQL結果當我執行以下操作:如何在CakePHP的2.0

$popular_posts = $this->Blog->find('all', array('limit' => 5)); 

我得到如下:

陣列

(
    [0] => Array 
     (
      [Blog] => Array 
       (
        [id] => 4fcfb37d-3eb0-4ec2-a744-175c987a2b72 
        [title] => This is a post example2 
        [short_description] => You've stumbled across our blog! Welcome! Here 
        [created] => 2012-06-06 21:46:05 
        [modified] => 2012-06-07 16:01:24 
       ) 

      [Reply] => Array 
       (
        [0] => Array 
         (
          [id] => 4fcfb305-0c58-421b-9149-175c987a2b72 
         ) 

        [1] => Array 
         (
          [id] => 4fd0ae9e-dca0-4afe-862c-1258987a2b72 
         ) 

       ) 

     ), 
    [1] ... 
    [2] ... 

) 

我如何訂購結果的答覆數量? (降序)?

回答

0

試試這個

$data = $this->Blog->find('all',array('group' =>array('Reply.id'), 
         'order' => array('COUNT(Reply.id) DESC'), 
         'limit'=> 5));