From 536ebdd0bd4fac4f9c09ec550ee930fcd663421d Mon Sep 17 00:00:00 2001 From: Thelonius Kort Date: Wed, 4 Jan 2023 15:29:14 +0100 Subject: [PATCH] Add foreign_key_constraint validation to Article and Translation --- lib/outlook/articles/article.ex | 1 + lib/outlook/translations/translation.ex | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/outlook/articles/article.ex b/lib/outlook/articles/article.ex index 8477089..2dfc7ce 100644 --- a/lib/outlook/articles/article.ex +++ b/lib/outlook/articles/article.ex @@ -23,5 +23,6 @@ defmodule Outlook.Articles.Article do article |> cast(attrs, [:title, :content, :url, :language, :date, :author_id]) |> validate_required([:title, :content, :url, :language, :date, :author_id]) + |> foreign_key_constraint(:author_id) end end diff --git a/lib/outlook/translations/translation.ex b/lib/outlook/translations/translation.ex index 3bac399..ba4b59a 100644 --- a/lib/outlook/translations/translation.ex +++ b/lib/outlook/translations/translation.ex @@ -29,5 +29,6 @@ defmodule Outlook.Translations.Translation do |> unique_constraint([:lang, :article_id], message: "translation for this language already exists", name: :article_id_lang_unique_index) + |> foreign_key_constraint(:article_id) end end