Add unique constraint to Translation
To make sure only one translation per article is possible.
This commit is contained in:
@ -26,5 +26,8 @@ defmodule Outlook.Translations.Translation do
|
||||
|> cast(attrs, [:lang, :title, :teaser, :date, :public, :unauthorized])
|
||||
|> cast(attrs, [:content], force_changes: true)
|
||||
|> validate_required([:lang, :title, :teaser, :content, :date, :public, :unauthorized])
|
||||
|> unique_constraint([:lang, :article_id],
|
||||
message: "translation for this language already exists",
|
||||
name: :article_id_lang_unique_index)
|
||||
end
|
||||
end
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
defmodule Outlook.Repo.Migrations.AddLangArticleIdUniqueIndexToTranslations do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create unique_index(:translations, [:article_id, :lang], name: :article_id_lang_unique_index)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user