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'
)
);
}
精彩评论