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
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
Copyright © 2021 Jogjafile Inc.
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. ;)