我想在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)
)
);
..但它只更新了最后一个字段。
答案 0 :(得分:1)
public $belongsTo = array(
'Table2' => array(
'className' => 'Table2',
'counterCache' => array(
'downvote_count' => true,
'upvote_count' => true
)
)
);