如何在表cakephp 2中使用counterCache更新两个字段?

时间:2012-05-18 12:22:36

标签: cakephp-2.0

我想在CakePHP 2.x中使用counterCache更新两个字段。我试过这段代码:

public $belongsTo = array(
    'Table2' => array(
        'className' => 'Table2',
        'counterCache' => 'downvote_count',
        'counterScope' => array('Table2.id' => 0)
    ),
    'Table2' => array(
        'className' => 'Table2',
        'counterCache' => 'upvote_count',
        'counterScope' => array('Table2.id' => 2)
    )
);

..但它只更新了最后一个字段。

1 个答案:

答案 0 :(得分:1)

public $belongsTo = array(
    'Table2' => array(
        'className' => 'Table2',
        'counterCache' => array(
            'downvote_count' => true,
            'upvote_count' => true
        )
    )
);