cakephp:使用counterCache命令

时间:2011-10-04 04:29:50

标签: cakephp cakephp-1.3 cakephp-1.2

我有两个模特。

以下模型descibe它们之间的关系。

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'
    )
 ); 
}

我在debate_posts表中创建了'no_of_comments'字段。

和 在DebatePost控制器中,

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

我按照上面的步骤2通过使用countercache找到辩论_发布数据命令而没有评论。但是没有得到任何结果。

1 个答案:

答案 0 :(得分:0)

'order'=>'DebatePost.no_of_comments DESC'
相关问题