Counter Problem

The fundamental problem is that in order to increment the counter when an existing record was associated, an extra query would be required to determine whether that record was already included in the count. At that point the performance gain of the counter is lost since you might as well just query for the COUNT again. Then there's the whole issue of deleting posts. I'm assuming the counter would not decrement unless you call @forum.posts.delete(id).

In my experience the counter caches are scarily brittle. If the given model is ONLY created through the association then they can be manageable and offer a slight performance benefit, but if you have the proper index, a COUNT(*) query is extremely fast.

> Do the counters update correctly on save?

Very much inline with what dasil said, the rails counters are very brittle, but they are typically per-object caches, so this should be alright. However, to be sure, I recommend in a unit test, trying out.

assert_equal @forum.posts.count, 1 assert_equal @topic.posts.count, 1

Your assertion may very well fail, but you should check log/test.log and examine what SQL queries Rails dispatched if any.