Skip to content

Commit c6b361e

Browse files
committed
feat: making schema.
1 parent c71caeb commit c6b361e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/blog_engine/post.ex

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
defmodule BlogEngine.Post do
22
use Ecto.Schema
33

4-
schema "posts" do
4+
import Ecto.Changeset
5+
6+
@required [:title, :content, :author_name]
7+
@optional [:tags]
8+
9+
schema "posts" do
510
field :title, :string
11+
field :content, :string
12+
field :author_name, :string
13+
14+
field :tags, :string
15+
16+
timestamps()
17+
end
18+
19+
def changeset(model \\ %__MODULE__{}, params) do
20+
model
21+
|> cast(params, @required ++ @optional)
22+
|> validate_required(@required)
23+
|> validate_length(:author, min: 3)
624
end
725
end

0 commit comments

Comments
 (0)