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

fix: prevent wrong returned entity in ReturningResultsEntityUpdator #6440

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/query-builder/ReturningResultsEntityUpdator.ts
Expand Up @@ -119,6 +119,13 @@ export class ReturningResultsEntityUpdator {
if (this.queryRunner.connection.driver.isReturningSqlSupported() === false && insertionColumns.length > 0) {
const entityIds = entities.map((entity) => {
const entityId = metadata.getEntityIdMap(entity)!;

// We have to check for an empty `entityId` - if we don't, the query against the database
// effectively drops the `where` clause entirely and the first record will be returned -
// not what we want at all.
if (!entityId)
throw new Error(`Cannot update entity because entity id is not set in the entity.`);

return entityId;
});

Expand Down