2012-07-13 74 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