I have a model that uses email as the primary key:
attribute :email, :string do
primary_key? true
allow_nil? false
constraints max_length: 255,
match: ~r/@/
end
In my registration form, I want to upsert: if the email address exists, just overwrite the other fields. I was hoping that something like this would work:
def handle_event("save", %{"form" => params}, socket) do
case AshPhoenix.Form.submit(socket.assigns.form,
upsert?: true,
upsert_identity: :email,
params: params) do
{:ok, _lead} ->
...
{:error, form} ->
...
end
Two questions:
- Is it possible to do an upsert, directly from AshPhoenix.Form.submit?
- If
upsert?
andupsert_identity
are invalid keys, why doesn’t this throw an error?
Sorry, I’ve been looking at the book and the docs, and haven’t been able to figure this out… Thank you!