Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: prevent wrong returned entity in ReturningResultsEntityUpdator (#…
…6440)

in the `ReturningResultsEntityUpdator` we have to check that the `entityId`
we pull from the entity is actually there.  if we don't we will create a
where clause that's undefined - effectively querying for every record
in the database and returning the wrong value
  • Loading branch information
imnotjames committed Sep 29, 2020
1 parent 44aff17 commit c1c8e88
Showing 1 changed file with 7 additions and 0 deletions.
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

0 comments on commit c1c8e88

Please sign in to comment.