Skip to content

Commit

Permalink
fix: prevent wrong returned entity in ReturningResultsEntityUpdator
Browse files Browse the repository at this point in the history
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 Jul 21, 2020
1 parent 9abab82 commit 96405cd
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/query-builder/ReturningResultsEntityUpdator.ts
Expand Up @@ -120,6 +120,12 @@ export class ReturningResultsEntityUpdator {
await Promise.all(entities.map(async (entity, entityIndex) => {
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.`);

// to select just inserted entity we need a criteria to select by.
// for newly inserted entities in drivers which do not support returning statement
// row identifier can only be an increment column
Expand Down

0 comments on commit 96405cd

Please sign in to comment.