diff --git a/app/controllers/admin/budget_investments_controller.rb b/app/controllers/admin/budget_investments_controller.rb index 2e5c17329..9f885f474 100644 --- a/app/controllers/admin/budget_investments_controller.rb +++ b/app/controllers/admin/budget_investments_controller.rb @@ -101,7 +101,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController end def load_investment - @investment = Budget::Investment.where(budget_id: @budget.id).find(params[:id]) + @investment = Budget::Investment.by_budget(@budget).find(params[:id]) end def load_admins diff --git a/app/helpers/budgets_helper.rb b/app/helpers/budgets_helper.rb index 7b48cad1a..85a727600 100644 --- a/app/helpers/budgets_helper.rb +++ b/app/helpers/budgets_helper.rb @@ -57,7 +57,7 @@ module BudgetsHelper end def investment_tags_select_options(budget) - Budget::Investment.where(budget_id: budget).tags_on(:valuation).order(:name).select(:name).distinct + Budget::Investment.by_budget(budget).tags_on(:valuation).order(:name).select(:name).distinct end def budget_published?(budget) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index bcc354cc8..a95f30f15 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -81,6 +81,7 @@ class Budget scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) } scope :by_tag, ->(tag_name) { tagged_with(tag_name) } scope :by_valuator, ->(valuator_id) { where("budget_valuator_assignments.valuator_id = ?", valuator_id).joins(:valuator_assignments) } + scope :by_budget, ->(budget) { where(budget: budget) } scope :for_render, -> { includes(:heading) } @@ -103,7 +104,7 @@ class Budget def self.scoped_filter(params, current_filter) budget = Budget.find_by(id: params[:budget_id]) || Budget.find_by(slug: params[:budget_id]) - results = Investment.where(budget_id: budget.id) + results = Investment.by_budget(budget) results = limit_results(budget, params, results) if params[:max_per_heading].present? results = results.where(group_id: params[:group_id]) if params[:group_id].present?