diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb index ac9ac6492..4c427759f 100644 --- a/app/models/budget/heading.rb +++ b/app/models/budget/heading.rb @@ -6,6 +6,20 @@ class Budget translates :name, touch: true include Globalizable + translation_class_delegate :budget + + class Translation + validate :name_uniqueness_by_budget + + def name_uniqueness_by_budget + if budget.headings + .joins(:translations) + .where(name: name) + .where.not("budget_heading_translations.budget_heading_id": budget_heading_id).any? + errors.add(:name, I18n.t("errors.messages.taken")) + end + end + end belongs_to :group diff --git a/app/models/budget/heading/translation.rb b/app/models/budget/heading/translation.rb deleted file mode 100644 index 3cf930f66..000000000 --- a/app/models/budget/heading/translation.rb +++ /dev/null @@ -1,14 +0,0 @@ -class Budget::Heading::Translation < Globalize::ActiveRecord::Translation - delegate :budget, to: :globalized_model - - validate :name_uniqueness_by_budget - - def name_uniqueness_by_budget - if budget.headings - .joins(:translations) - .where(name: name) - .where.not("budget_heading_translations.budget_heading_id": budget_heading_id).any? - errors.add(:name, I18n.t("errors.messages.taken")) - end - end -end