cakephp: Order by using counterCache
I have two model.
Below Model descibe Relation between them.
class DebatePost extends AppModel {
var $name = 'DebatePost';
var $hasMany = array(
'DebateComment' => array(
'className' => 'DebateComment',
'foreignKey' => 'debate_id',
'dependent'=> true,
)
);
}
class DebateComment extends AppModel {
var $name = 'DebateComment';
var $belongsTo = array(
'DebatePost' => array(
'className' => 'DebatePost',
'foreignKey' => 'debate_id',
'dependent' => true,开发者_C百科
'counterCache' => 'no_of_comments'
)
);
}
And I created 'no_of_comments' field in debate_posts table.
And In DebatePost controller,
$arrde = $this->DebatePost->find('all',array('order'=>'debat_posts.no_of_comments DESC'));
i follow above step two find debate_posts data orderby no of comments in debate_comments by using countercache.but didnt get any result.
'order'=>'DebatePost.no_of_comments DESC'
精彩评论