Skip to content

Instantly share code, notes, and snippets.

@sobolevn
Created July 19, 2017 13:59
Show Gist options
  • Save sobolevn/b6bf8b30d207f42062a5de1f473bb2ae to your computer and use it in GitHub Desktop.
Save sobolevn/b6bf8b30d207f42062a5de1f473bb2ae to your computer and use it in GitHub Desktop.
defmodule EctoSlugs.Blog.Article do
use Ecto.Schema
import Ecto.Changeset
alias EctoSlugs.Blog.Article
schema "blog_articles" do
field :breaking, :boolean, default: false
field :content, :string
field :title, :string
timestamps()
end
@doc false
def changeset(%Article{} = article, attrs) do
article
|> cast(attrs, [:title, :content, :breaking])
|> validate_required([:title, :content])
|> unique_constraint(:title)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment