Created
July 19, 2017 13:59
-
-
Save sobolevn/b6bf8b30d207f42062a5de1f473bb2ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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