Ash FrameworkAF
Ash Framework3y ago
5 replies
Arjun Bajaj

Only change a few fields `ON CONFLICT` in an Upsert

Let's say I am implementing GitHub login myself. I have a User resource with a few attributes, and its create action is an upsert. Its working and Ash generates the right query, however, I want Ash to not include a few fields in the ON CONFLICT part.

This is the query Ash generates:

INSERT INTO "users" AS u0 ("email","full_name","gh_access_token","gh_id","gh_scope","id","username") VALUES ($1,$2,$3,$4,$5,$6,$7) ON CONFLICT ("gh_id") DO UPDATE SET "email" = $8, "full_name" = $9, "gh_access_token" = $10, "gh_id" = $11, "gh_scope" = $12, "username" = $13 RETURNING ...


I would instead want this (only two fields instead of all):
... ON CONFLICT ("gh_id") DO UPDATE SET "gh_access_token" = $10, "gh_scope" = $12 RETURNING ...


How would I go about doing this?

This is my current action:

create :gh_login do
  accept [:gh_id, :email, :username, :full_name, :gh_access_token, :gh_scope]

  upsert? true
  upsert_identity :unique_gh_id
end
Was this page helpful?