Move Translation class inside Budget

The reason to move Translation class is explained here [1]

[1] 106649a8a5
This commit is contained in:
Senén Rodero Rodríguez
2019-04-01 11:59:11 +02:00
committed by voodoorai2000
parent 3b03e583f9
commit 0011a0b4c7

View File

@@ -229,4 +229,16 @@ class Budget < ApplicationRecord
slug.nil? || drafting?
end
class Translation < Globalize::ActiveRecord::Translation
validate :name_uniqueness_by_budget
def name_uniqueness_by_budget
if Budget.joins(:translations)
.where(name: name)
.where.not("budget_translations.budget_id": budget_id).any?
errors.add(:name, I18n.t("errors.messages.taken"))
end
end
end
end