Fixes #5692 - correct counts in cached_counters

This was caused by a rails bug. (https://github.com/rails/rails/issues/9722)
Also fixes related bugs #6210, #6716 and #6813.
We should consider creating a migration to clean up any incorrect cached counters caused by these bugs.
Once we upgrade to rails 4.x we can remove this mixin.
nitpick, I suggest to use `.scoped` rather than `.all` since `.all` returns an array and can't be chained, whereas `.scoped` returns an AR object and can be chained. I think in Rails 4, `.all` returns an AR object, so this isn't a big deal.