CakePHP:如何查找按相关模型数量排序的列


CakePHP: How to find columns ordered by number of related models?

我希望有人能帮助我。我有两个表格网站和点赞。每个网站都有点赞。我不知道怎样才能让所有网站按点赞数排序。这对我来说听起来很基本,但我没能找到解决方案。。。

下面是我最后一次尝试的内容(模型中包含的actsas可用):

$this->paginate = array('contain' => array(
    'Like' => array(
         'order' => array('count(Like.id) DESC')
    )
));
$this->set('websites', $this->paginate());

有人能帮帮我吗?

欢呼。Andreas

//更新我找到了解决办法。我现在使用计数器缓存。对于那些感兴趣的人应该counterCache-在这里缓存你的计数(),这是我的代码

$this->paginate = array(
    'order' => array('like_count' => 'desc'),
    'limit' => 15
);
$this->set('websites', $this->paginate());

我找到了一个解决方案。我现在使用计数器缓存。对于那些感兴趣的人应该阅读counterCache-在这里缓存你的计数(),这是我的代码

$this->paginate = array(
     'order' => array('like_count' => 'desc'),
     'limit' => 15
);
$this->set('websites', $this->paginate());