Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upsert with conflict on ID #5607

Closed
petersamokhin opened this issue Jun 6, 2023 · 1 comment
Closed

upsert with conflict on ID #5607

petersamokhin opened this issue Jun 6, 2023 · 1 comment

Comments

@petersamokhin
Copy link

petersamokhin commented Jun 6, 2023

hello there! I would like to perform a very basic operation: insert a record into the database and update it if there is a conflict on the ID.
I thought allow_user_specified_id could help, however, it didn't:

UnsupportedFeatureError: UNLESS CONFLICT can not use ELSE when constraint is from a parent type

I then tried to duplicate the ID property using overloaded, and add a constraint (both inside the property {} declaration OR separately like constraint exclusive on (.id), — nothing works.

I see no other option apart from creating and maintaining my own IDs for every object.
What am I doing wrong?

I'm ok with not specifying the IDs myself, however, I need to be able to do upserts without duplicating the objects by updating them by ID if they exist already.

The duplicating ID approach is also weird because you cannot just create a new abstract type with a property e.g. uid — it will not work again, because the constraint will be on the parent type, again 🙃
So it is gonna lead to tons of duplicated code (4 lines per each object type declaration, which is a lot)

@msullivan
Copy link
Member

This issue is discussed in #4302
The crux of the issue is that if something conflicts with .id, it might come from a different type, not the one you care about. We haven't come to a firm conclusion what the best way to deal with this question is, though there are options.

Probably your best workaround now is to use the new 4.0 feature of using ?? with DML on the RHS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants