tesserakt
tesserakt

Reputation: 3331

Rails cache_counter not decrementing?

I have a cache counter setup for a Posts class on the comments field. Posts have many comments, and a comment belongs to a post.

If I add a new comment to a post and save, the counter gets incremented, but if I delete an individual comment, the counter is not touched. Is this not provided automatically, or do I have to roll me own decrementor when working with counter_cache?

Rails 2.3.2

Thank you!

Upvotes: 0

Views: 276

Answers (1)

Jamie Wong
Jamie Wong

Reputation: 18350

How are you deleting the comment?

You should know that ActiveRecord::Base delete and destroy are not the same thing. Delete won't go through any callbacks, so it won't update the cache counter.

Upvotes: 3

Related Questions