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!
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.
精彩评论