我有以下数据库结构:
用户
id, username, ..., silver_medal_counter, gold_medal_counter, bronze_medal_counter
徽章
id, name, description, points, medal (silver, gold, bronze)
Userbadges
id, user_id, badge_id, created
如果添加了userbadge,则counterCache应更新users表中的相关medal_counter字段。
我有什么:
class Userbadge extends AppModel {
public $belongsTo = array(
'User' => array(
'counterCache' => array(
'silver_medal_counter' => array('Userbadge.Badge.medal' => 'silver'),
'gold_medal_counter' => array('Userbadge.Badge.medal' => 'gold'),
'bronze_medal_counter' => array('Userbadge.Badge.medal' => 'bronze')
)
),
'Badge' => array('className' => 'Badge')
);
}
注意:包含$actAs = array('Containable');
。我正在使用cakephp 2.5.6
。
我该如何解决这个问题?