Very weird counter_cache behavior

Hi All,

I’m using a counter_cache, which I believe I’m doing correctly because I
can see this SQL query being executed in the development.log file:

UPDATE gifts SET bookmarks_count = bookmarks_count + 1 WHERE (id = 276)

However, in the gifts table, the bookmarks_count field isn’t incremented
(it’s zero). If I literally copy and paste that query into the MySQL
Query browser, it works and increments the value.

Does anyone have any idea how that could happen?


Based on what I’ve been reading, it sounds like counter caches are
horribly broken and unreliable. Anytime you try and save an object, it
overwrites the counter cache with zero.

Also, rails seems to be finicky about how you associate things so the
counter cache gets set (not that it matters, since it’s just going to be

So, that’s kind of a bummer, because I think it’s a fairly important
feature. If anyone has had any sucess with them, I’d love to hear about

Tom L. [email protected] writes:

Does anyone have any idea how that could happen?

Make sure the transaction is being committed and not rolled back.


Surendra S.,
Read my blog at:
| Ans: Saving the tiger means saving mankind…
| Help
| or