开发者

Rails cache_counter not decrementing?

开发者 https://www.devze.com 2023-01-03 20:07 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号