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
Control the column on upsert #4602
Comments
What you can do now is to pass in DTO without the id and let the database generate it (you will need a default for the id on db level). const customer = await em.upsert(Customer, { email: '...' }); Note that in your code, |
I would like to generate uuidv7, which is not yet supported natively (I generate it server side). |
I will add 4 new options:
Which should make the upsert queries completely configurable. Already have a WIP that handles the queries correctly, the tricky part will be handling the entity mapping (both to existing entity instances and to the POJO signatures) and reloading the missing data (for mysql that does not have a returning clause). This should cover also #4325, which is about being able to omit a field from the merge data. |
Thanks a lot, this looks like a perfect solution to this problem! Great job! |
Adds 4 new options to `em.upsert()`: - `onConflictFields?: (keyof T)[]` to control the conflict clause - `onConflictAction?: 'ignore' | 'merge'` used ignore and merge as that is how the QB methods are called - `onConflictMergeFields?: (keyof T)[]` to control the merge clause - `onConflictExcludeFields?: (keyof T)[]` to omit fields from the merge clause Closes #4325 Closes #4602
Hi !
I have an entity where I generate the UUID on application side (can't use database generation), where the email is the unique field. I try to do the upsert like this:
However MikroORM generate this SQL:
However, I would like MikroORM to check the conflict on the email, not the ID, so generate this query:
Is there a way to override the column that MikroORM is using? Maybe somehing like that:
Thanks!
The text was updated successfully, but these errors were encountered: