Counter_cache deprecated in after_create hook

I rely on the cache counter value in my model's hook_out_create. However, my hook is called before the counter cache is updated, thereby breaking the calculations.

Is there a way to make the cache counter "reset" so that I always see the last value in after_create?

+3
source share
1 answer

Make sure your operator after_create :callbackis located after the definition has_many/belongs_to.

If this does not work, you can create your own counting cache (this is nothing more than a call for increase / decrease, see add_counter_cache_callbacks ) and make sure that it is called before your code.

+3
source

Source: https://habr.com/ru/post/1733543/


All Articles