2012-07-13 75 views
1

嗨,我在2.0中使用Countercache我需要添加一些條件如下。 但它不起作用。如果'counterCache'=> true它增加字段,它不考慮我添加的條件。Cakephp Countercache問題

後的hasMany WallPost

WallPost屬於發佈

public $belongsTo = array(
    'WallPost' => array(
     'className' => 'WallPost', 
     'foreignKey' => 'wallpost_id', 
     'counterScope' =>array(
      'WallPost.post_id' =>3, 
     ), 
     'fields' => '', 
     'order' => '', 
     'counterCache' => true 
    ), 
+0

我已經檢查了cakephp文檔在1.3中,我發現了有關計數器緩存的問題,並且它的正確性依據1.3,但在2.0中,我無法找到任何與計數器緩存相關的主題。 – Vins 2012-07-13 11:55:07

+2

看起來很好根據2.0的書以及:http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html – Dave 2012-07-13 13:18:12

+0

是的我經歷了食譜,但無法找到任何解決方案:( – AnNaMaLaI 2012-07-13 13:34:54

回答

3

你想要的是:

public $belongsTo = array(
'WallPost' => array(
    'className' => 'WallPost', 
    'foreignKey' => 'wallpost_id', 
    'fields' => '', 
    'order' => '', 
    'counterCache' => array('WallPost.post_id' =>3) 
), 

你是正確的,雖然該文檔在這個混亂。

+0

這很奇怪,我正在使用它,並且它工作正常。 – 2012-08-31 11:48:09