Skip to content

Commit

Permalink
correctly handle composite PK & failed entity loads
Browse files Browse the repository at this point in the history
  • Loading branch information
imnotjames committed Sep 15, 2020
1 parent cbfbc56 commit 51da0ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/query-builder/ReturningResultsEntityUpdator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ export class ReturningResultsEntityUpdator {
// for postgres and mssql we use returning/output statement to get values of inserted default and generated values
// for other drivers we have to re-select this data from the database
if (this.queryRunner.connection.driver.isReturningSqlSupported() === false && insertionColumns.length > 0) {
const entityIds = entities.map((entity) => {
let entityIds: any[] = entities.map((entity) => {
const entityId = metadata.getEntityIdMap(entity)!;
return entityId;
});

// TODO: This is to make the behavior match current behavior of the `next` branch
// TODO: It's technically not correct but is put in place during the merge to keep behavior the same
entityIds = entityIds.filter(e => typeof e !== "undefined");

// to select just inserted entities 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
2 changes: 1 addition & 1 deletion src/query-builder/SelectQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> implements
where(where: Brackets|string|((qb: this) => string)|FindOptionsWhere<Entity>, parameters?: ObjectLiteral): this {
this.expressionMap.wheres = []; // don't move this block below since computeWhereParameter can add where expressions

if (where && typeof where === "object" && !(where instanceof Brackets)) {
if (where && typeof where === "object" && !(where instanceof Brackets) && !Array.isArray(where)) {
this.findOptions.where = where;

} else {
Expand Down

0 comments on commit 51da0ab

Please sign in to comment.