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

The names of entity properties are not converted to column names when used in the qb.onConflict method #4483

Closed
mrmlnc opened this issue Jun 25, 2023 · 0 comments

Comments

@mrmlnc
Copy link

mrmlnc commented Jun 25, 2023

Describe the bug

The names of entity properties are not converted to column names when used in the qb.onConflict method.

At the same time, TS types indicate that I can use entity field names.

await orm.em.createQueryBuilder(UserEntity)
    .insert([{ externalId: '1', organization: 1 }, { externalId: '2', organization: 1 }])
    // Entity field – column name
    // externalId – external_id
    // organization – organization_id
    // 
    // TS types: externalId, id, organization 
    .onConflict(['externalId', 'organization'])
    .ignore()
    .execute();

Stack trace

insert into "user" ("external_id", "organization_id") values ('1', 1), ('2', 1)
on conflict ("externalId", "organization") do nothing returning "id" - column "externalId" does not exist

To Reproduce

📖 I have a repository that makes it easy to reproduce the problem:
https://github.com/mrmlnc/mikro-orm-onConflict-mapper-issue

Steps to reproduce the behavior:

  1. git clone https://github.com/mrmlnc/mikro-orm-onConflict-mapper-issue
  2. npm ci
  3. npm start

Expected behavior

I expect to be able to use entity field names in this method.

Additional context

It looks like the bug is here:

const sub = item.fields.length > 0 ? qb.onConflict(item.fields) : qb.onConflict();

The mapper is not used here when passing fields to QB. In other methods it is used.

Also the problem can be reproduced in V6.

Versions

Dependency Version
node 16.16.0
typescript 4.7.4
mikro-orm 5.7.12
your-driver postgresql
@mrmlnc mrmlnc changed the title The names of entity properties are not converted to column names when used in the qb.onConflict method. The names of entity properties are not converted to column names when used in the qb.onConflict method Jun 25, 2023
@B4nan B4nan closed this as completed in e38d126 Aug 27, 2023
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

1 participant