1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-11 09:32:51 +00:00

create thread migration

This commit is contained in:
2018-01-01 20:50:50 -06:00
parent e77288d40e
commit 3a61151191
3 changed files with 48 additions and 0 deletions

28
lib/myapp/data/thread.ex Normal file
View File

@@ -0,0 +1,28 @@
defmodule MyApp.Data.Thread do
use Ecto.Schema
import Ecto.Query
import Ecto.Changeset
alias MyApp.Repo
alias MyApp.Data
@derive {Poison.Encoder, except: [:__meta__]}
schema "thread" do
field :title, :string
field :content, :string
field :view_count, :integer
field :user_id, :integer
field :last_reply_id, :integer
field :sticky, :boolean, default: false
field :locked, :boolean, default: false
belongs_to :user, Data.User, define_field: false
timestamps()
end
def changeset(thread, params \\ %{}) do
thread
|> cast(params, [:title, :content, :user_id, :view_count, :last_reply_id, :sticky, :locked])
|> validate_required([:title, :content, :user_id])
end
end