fix(models): prevent IDs being empty while inserting
Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
parent
99ad54cf68
commit
d818c7033a
@ -2,6 +2,8 @@ defmodule Ketbin.Pastes.Paste do
|
|||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
@primary_key {:id, :string, autogenerate: false}
|
||||||
|
@derive {Phoenix.Param, key: :id}
|
||||||
schema "pastes" do
|
schema "pastes" do
|
||||||
field :content, :string
|
field :content, :string
|
||||||
field :is_url, :boolean, default: false
|
field :is_url, :boolean, default: false
|
||||||
@ -11,7 +13,7 @@ defmodule Ketbin.Pastes.Paste do
|
|||||||
@doc false
|
@doc false
|
||||||
def changeset(paste, attrs) do
|
def changeset(paste, attrs) do
|
||||||
paste
|
paste
|
||||||
|> cast(attrs, [:is_url, :content])
|
|> cast(attrs, [:is_url, :content, :id])
|
||||||
|> validate_required([:is_url, :content])
|
|> validate_required([:is_url, :content])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,6 +15,7 @@ defmodule KetbinWeb.PasteController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create(conn, %{"paste" => paste_params}) do
|
def create(conn, %{"paste" => paste_params}) do
|
||||||
|
# paste_params = Map.put(paste_params, "id", s)
|
||||||
case Pastes.create_paste(paste_params) do
|
case Pastes.create_paste(paste_params) do
|
||||||
{:ok, paste} ->
|
{:ok, paste} ->
|
||||||
conn
|
conn
|
||||||
|
Loading…
Reference in New Issue
Block a user