Why does this fail:
%Partner{} |> cast(%{id: 123}, [:id]) |> delete
with a Ecto.NoPrimaryKeyValueError? I'm setting the primary key explicitly?
Ecto.NoPrimaryKeyValueError
For changesets, the id from the original struct (data) is used by Repo.delete, and not the one in changes, and cast puts the new id only in changes. You can either merge changes into the original struct (data):
id
data
Repo.delete
changes
cast
%Partner{} |> cast(%{id: 123}, [:id]) |> Ecto.Changeset.apply_changes |> delete
or put the id into %Partner{} manually:
%Partner{}
%Partner{id: 123} |> delete
Copyright © 2021 Jogjafile Inc.
For changesets, the
id
from the original struct (data
) is used byRepo.delete
, and not the one inchanges
, andcast
puts the newid
only inchanges
. You can either mergechanges
into the original struct (data
):or put the
id
into%Partner{}
manually: