cakephp Counter cache in nested model
i have nested model structure
id
parent_id
counter
name开发者_StackOverflow中文版
how to use automated counter cache
Define it in the relationship definition.
<?php
class YourModel extends AppModel {
var $belongsTo = array(
'ParentModel' => array(
'foreignKey' => 'your_model_id',
'className' => 'ParentModel',
'counterCache' => 'counter'
)
)
);
}
?>
Where 'counter' is the field in your table that contains the count.
精彩评论