JOL/lib/jol/blog/post.ex

23 lines
511 B
Elixir

defmodule JOL.Blog.Post do
use Ecto.Schema
import Ecto.Changeset
schema "posts" do
field :title, :string
field :body, :string
field :published_at, :naive_datetime
field :slug, :string
many_to_many :tags, JOL.Blog.Tag, join_through: "post_tags"
timestamps(type: :utc_datetime)
end
@doc false
def changeset(post, attrs) do
post
|> cast(attrs, [:title, :body, :published_at, :slug])
|> validate_required([:title, :body, :slug])
|> cast_assoc(:tags)
end
end