Search code examples
phpcakephpcounter-cache

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',
counterScope => 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?


Solution

  • 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.