在cakecan I counterCache相关模型?例如:用户->;轮廓


In cakecan I counterCache related models? eg: User -> Profile

我的countries表上有一个字段member_count

Profile属于Country

counterCache => 'member_count',
counterScope => array( 'Profile.country => 'US' )

因此,当用户在$this->User->Profile->save( $this->data)上运行保存时,我希望更新Country中的counterCache

可能吗?

Barry在文档中没有被列为hasMany关系的选项

我想你可以缓存一个包含国家/地区结果及其配置文件数量的视图,以节省一些性能作为替代方案。

请重新查看文档以确保您做得很好。

你的个人资料模型应该是这样的:

function Profile extends AppModel {
    $name = 'Profile';
    var $belongsTo = array(
        'Country' => array(
            'counterCache' => 'member_count'
        )
    );
}