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?

Thanks!
Tom

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.

http://dev.rubyonrails.org/ticket/5050

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

http://lists.rubyonrails.org/pipermail/rails/2006-March/027450.html

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
it.

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.

Cheers,

Surendra S.
http://ssinghi.kreeti.com, http://www.kreeti.com
Read my blog at: http://cuttingtheredtape.blogspot.com/
,----
| WHY SHOULD WE SAVE TIGER?
| Ans: Saving the tiger means saving mankind…
|
| Help http://pudang.tripod.com/
| or https://secure.worldwildlife.org/forms/tiger_appeal_1.cfm
`----

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs