Cakephp hasAndBelongsToMany with countercache?

659 Views Asked by At

Anyone know how to get countercache working on HABTM setup?

- categories
;id, name, test_count

- tests
; id, name

- test_to_categories
; test_id, category_id
1

There are 1 best solutions below

1
On

Use the counter cache in your join model (test_to_categories) through the belongsTo associations.

If that does not do the job for you then you'll have to implement a custom counter method and call it in the afterSave() of the model that should get a count updated.

By the way "test_to_categories" is not following the conventions. It should be categories_tests. The conventions are there for a reason. ;)