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

OnConflictColumns.UpdateNewValues doesn't work in MapCreateBulk #4011

Open
2 tasks done
w7089 opened this issue Apr 11, 2024 · 0 comments
Open
2 tasks done

OnConflictColumns.UpdateNewValues doesn't work in MapCreateBulk #4011

w7089 opened this issue Apr 11, 2024 · 0 comments

Comments

@w7089
Copy link

w7089 commented Apr 11, 2024

entity.SomeFIeld has unique index index defined. So on insert of entities with the same value of SomeFIeld, i'd expect UNIQUE constraint failed to be raised.

However, for upserts, i'd like the other columns to be overriden with the new values.

While using below code to achieve bulk insert while allowing upserts, i'm getting UNIQUE constraint failed.

_, err = dal.db.Entity.MapCreateBulk(entitiesData, func(create *ent.entityCreate, i int) {
    _, err := entityCreate.
        SetField1(entitiesData[i].some).
        ...
        OnConflictColumns(entity.SomeFIeld).
        UpdateNewValues()

}).Save(ctx)

Doing insert one by one doesn't result in this error:

for _, test := range  `entitiesData`{
    _, err := dal.db.entities.
        Create().
        SetField1(test.some)
        OnConflictColumns((entity.SomeFIeld).
        UpdateNewValues().ID(ctx)
}
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

UNIQUE constraint failed raised

Expected Behavior 🤔

no UNIQUE constraint failed raised

Your Environment 🌎

Tech Version
Go go1.21.7
Ent v0.12.5
Database Posgres
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