开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜