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.
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
overwritten):