cakephp: упорядочить с помощью counterCache

#cakephp #cakephp-1.3 #cakephp-1.2

#cakephp #cakephp-1.3 #cakephp-1.2

Вопрос:

У меня есть две модели.

Ниже приведена модель, описывающая связь между ними.

 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,
        'counterCache' => 'no_of_comments'
    )
 ); 
}
  

И я создал поле ‘no_of_comments’ в таблице debate_posts.

И в контроллере DebatePost,

 $arrde = $this->DebatePost->find('all',array('order'=>'debat_posts.no_of_comments DESC'));
  

я следую приведенному выше шагу два, нахожу порядок данных debate_posts без комментариев в debate_comments с помощью countercache.но не получил никакого результата.

Ответ №1:

 'order'=>'DebatePost.no_of_comments DESC'