2

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
Tom
  • 3,717
  • 5
  • 26
  • 28

1 Answers1

1

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. ;)

floriank
  • 25,546
  • 9
  • 42
  • 66