Has there ever been discussion of adding a method to recalculate
counter cache values?
This seems like it would be useful both for adding counter caches to
existing tables, and also for fixing things up when direct SQL
manipulations are used (performance reasons in my case).
There are actually two parts to the problem. The simple part is that
the update_counters only supports incremental change, so doing a full
reset would require some awkward arithmetic.
The more complex part is using the association reflections to
calculate the actual value automatically. Doing so would require the
participation of both the belongs_to reflection *and* the has_many
reflection, which I can see being a bit smelly given the fact that the
counter cache currently works without the need for has_many to be
declared at all. However I think it's utility might outweigh the
complexity...
What do you guys think?