fix(models): prevent IDs being empty while inserting

Signed-off-by: SphericalKat <amolele@gmail.com>
This commit is contained in:
Amogh Lele 2021-08-12 04:29:58 +05:30
parent 99ad54cf68
commit d818c7033a
No known key found for this signature in database
GPG Key ID: ED5C54FBBB920E51
2 changed files with 4 additions and 1 deletions

View File

@ -2,6 +2,8 @@ defmodule Ketbin.Pastes.Paste do
use Ecto.Schema
import Ecto.Changeset
@primary_key {:id, :string, autogenerate: false}
@derive {Phoenix.Param, key: :id}
schema "pastes" do
field :content, :string
field :is_url, :boolean, default: false
@ -11,7 +13,7 @@ defmodule Ketbin.Pastes.Paste do
@doc false
def changeset(paste, attrs) do
paste
|> cast(attrs, [:is_url, :content])
|> cast(attrs, [:is_url, :content, :id])
|> validate_required([:is_url, :content])
end
end

View File

@ -15,6 +15,7 @@ defmodule KetbinWeb.PasteController do
end
def create(conn, %{"paste" => paste_params}) do
# paste_params = Map.put(paste_params, "id", s)
case Pastes.create_paste(paste_params) do
{:ok, paste} ->
conn