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

afterInsert called with the same entity in batch inserts #6578

Closed
Nosfistis opened this issue Aug 18, 2020 · 3 comments
Closed

afterInsert called with the same entity in batch inserts #6578

Nosfistis opened this issue Aug 18, 2020 · 3 comments

Comments

@Nosfistis
Copy link

Issue type:

[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I am using TypeORM with NestJS. I have a subscriber implementing the EntitySubscriberInterface, specifically the afterInsert. When inserting multiple values at once using repository.insert(values), the afterInsert is called as many times as the values, but the attached entity is always the first of them. I have not found any other way to retrieve the entities inserted.

@Nosfistis
Copy link
Author

After some investigation, the InsertResult from repository.insert(values) itself contains an array with the same generated map multiple times. The SELECT query performed after the insert uses the first id as well, so that's causing the issue.

This does not occur in repository.save operations.

This was tested in MariaDB 10.5.

@dolsup
Copy link
Contributor

dolsup commented Sep 4, 2020

related to #6266
duplicate of #2131

@imnotjames
Copy link
Contributor

Duplicate of #2131

Closed.

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

No branches or pull requests

3 participants