开发者

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

开发者 https://www.devze.com 2023-03-11 10:19 出处:网络
I have a field member_count on my countries table. Profile belongsTo Country counterCache => \'member_count\',

I have a field member_count on my countries table.

Profile belongsTo Country

counterCache => 'member_count',
counterS开发者_JAVA百科cope => array( 'Profile.country => 'US' )

So, when a user runs a save on $this->User->Profile->save( $this->data), i would like to update the counterCache in Country.

Possible?


Barry its not listed as an option on a hasMany relationship in the documentation

I suppose you could cache a view with the results of the countries and their number of profiles to save you some performance as an alternative.


Please have another look in the documentation to make sure, you did everything right.

Your Profile-Model should look like this:

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

精彩评论

暂无评论...
验证码 换一张
取 消