0
我的問題是,我想爲一篇文章的評論數票。 因此,用戶可以upvote文章的好評,我想列出最先得票最多的評論。我現在遵循的方法正在工作,限制只有投票已經被投票。那些沒有列在連接表(comments_users)中的被忽略。 使其更有點清楚我的表是用戶,評論和HABTM連接表comments_users(化名票)Cakephp通過加入結果數量的順序包括不存在的條目
我目前的做法是:
public function commentsOfArticle($articleId){
$options['group'] = array('Comment.articleId');
$options['conditions'][] = array('Comment.article_id' => $articleId);
$options['joins'][] = array('table' => 'comments_users',
'alias' => 'Votes',
'type' => 'inner',
'conditions' => array(
'Votes.comment_id = Comment.id'
));
$options['fields'] = array('Comment.*','COUNT(Votes.user_id) AS votes');
$options['contain'] = array(.......);
$options[ 'order'] = array('votes DESC');
return $this->find('all',$options);
}
我認爲關鍵行是
$options['fields'] = array('Comment.*','COUNT(Votes.user_id) AS votes');
是否有可能接收那些評論,沒有條目中的投票t能夠在我的結果結束時,只有票數= 0?