diff --git a/app/models/budget/group.rb b/app/models/budget/group.rb index 37d6e658b..d316d2512 100644 --- a/app/models/budget/group.rb +++ b/app/models/budget/group.rb @@ -4,6 +4,19 @@ 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.groups.joins(:translations) + .where(name: name) + .where.not("budget_group_translations.budget_group_id": budget_group_id).any? + errors.add(:name, I18n.t("errors.messages.taken")) + end + end + end belongs_to :budget diff --git a/app/models/budget/group/translation.rb b/app/models/budget/group/translation.rb deleted file mode 100644 index 36489eb10..000000000 --- a/app/models/budget/group/translation.rb +++ /dev/null @@ -1,13 +0,0 @@ -class Budget::Group::Translation < Globalize::ActiveRecord::Translation - delegate :budget, to: :globalized_model - - validate :name_uniqueness_by_budget - - def name_uniqueness_by_budget - if budget.groups.joins(:translations) - .where(name: name) - .where.not("budget_group_translations.budget_group_id": budget_group_id).any? - errors.add(:name, I18n.t("errors.messages.taken")) - end - end -end