From 4ec30a908207ca8e779a62577a6d8644fe47fc59 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 31 Jan 2018 01:46:47 +0100 Subject: [PATCH] Avoid using comments_count counter_cache at Investment As Budget::Investment has two relationships over commentable polymorphic relationship, the counter_cache is counting the sum of both comments and valuations. We don't show valuations count anywhere, only the (public) comments so we just use comments.count in this case --- app/models/budget/investment.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 7129c40dc..f909a9746 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -89,6 +89,10 @@ class Budget before_validation :set_responsible_name before_validation :set_denormalized_ids + def comments_count + comments.count + end + def url budget_investment_path(budget, self) end