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
For changesets, the
idfrom the original struct (data) is used byRepo.delete, and not the one inchanges, andcastputs the newidonly inchanges. You can either mergechangesinto the original struct (data):or put the
idinto%Partner{}manually: