2012-05-18 64 views
1

我想在CakePHP 2.x中使用counterCache更新兩個字段。我試過這個代碼:如何在表cakephp 2中使用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
public $belongsTo = array(
    'Table2' => array(
     'className' => 'Table2', 
     'counterCache' => array(
      'downvote_count' => true, 
      'upvote_count' => true 
     ) 
    ) 
);