Files
phoenix-ausblick/lib/outlook/articles/article.ex
2023-01-11 19:11:07 +01:00

29 lines
761 B
Elixir

defmodule Outlook.Articles.Article do
use Ecto.Schema
import Ecto.Changeset
alias Outlook.Articles.InternalTree
alias Outlook.Authors.Author
alias Outlook.Translations.Translation
schema "articles" do
field :content, InternalTree
field :date, :utc_datetime
field :language, :string, default: "EN"
field :title, :string
field :url, :string
belongs_to :author, Author
has_many :translations, Translation, on_delete: :delete_all
timestamps()
end
@doc false
def changeset(article, attrs) 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