From 767fd04bdfe957f43dce4a3e73c273dda27a1631 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Mon, 29 Jan 2018 21:55:51 +0100 Subject: [PATCH] Add valuation comments relation at Budget Investment Why: Budget Investments already has an existing `comments` relation that is on use. We need to keep that relation unaltered after adding the internal valuation comments, that means scoping the relation to only public comments (non valuation ones) so existing code using it will remain working as expected. A new second relation will be needed to explicitly ask for valuation comments only where needed, again scoping to valuation comments. How: Adding a second `valuations` relationship and filtering on both with the new `valuation` flag from Comment model. --- app/models/budget/investment.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 58674be9b..7129c40dc 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -34,7 +34,10 @@ class Budget has_many :valuator_assignments, dependent: :destroy has_many :valuators, through: :valuator_assignments - has_many :comments, as: :commentable + + has_many :comments, -> {where(valuation: false)}, as: :commentable, class_name: 'Comment' + has_many :valuations, -> {where(valuation: true)}, as: :commentable, class_name: 'Comment' + has_many :milestones validates :title, presence: true