Skip to content

Commit

Permalink
fix mongo ormutils calls
Browse files Browse the repository at this point in the history
  • Loading branch information
imnotjames committed Jun 29, 2021
1 parent 314024f commit 43a39f5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/persistence/SubjectExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export class SubjectExecutor {

// for mongodb we have a bit different updation logic
if (this.queryRunner instanceof MongoQueryRunner) {
const partialEntity = OrmUtils.mergeDeep({}, subject.entity);
const partialEntity = this.cloneSubjectEntity(subject);
if (subject.metadata.objectIdColumn && subject.metadata.objectIdColumn.propertyName) {
delete partialEntity[subject.metadata.objectIdColumn.propertyName];
}
Expand Down Expand Up @@ -540,6 +540,18 @@ export class SubjectExecutor {
}
}

private cloneSubjectEntity(subject: Subject): ObjectLiteral {
const target: ObjectLiteral = {};

if (subject.entity) {
for (const column of subject.metadata.columns) {
OrmUtils.mergeDeep(target, column.getEntityValueMap(subject.entity));
}
}

return target;
}

/**
* Soft-removes all given subjects in the database.
*/
Expand All @@ -551,7 +563,7 @@ export class SubjectExecutor {

// for mongodb we have a bit different updation logic
if (this.queryRunner instanceof MongoQueryRunner) {
const partialEntity = OrmUtils.mergeDeep({}, subject.entity);
const partialEntity = this.cloneSubjectEntity(subject);
if (subject.metadata.objectIdColumn && subject.metadata.objectIdColumn.propertyName) {
delete partialEntity[subject.metadata.objectIdColumn.propertyName];
}
Expand Down Expand Up @@ -631,7 +643,7 @@ export class SubjectExecutor {

// for mongodb we have a bit different updation logic
if (this.queryRunner instanceof MongoQueryRunner) {
const partialEntity = OrmUtils.mergeDeep({}, subject.entity);
const partialEntity = this.cloneSubjectEntity(subject);
if (subject.metadata.objectIdColumn && subject.metadata.objectIdColumn.propertyName) {
delete partialEntity[subject.metadata.objectIdColumn.propertyName];
}
Expand Down

0 comments on commit 43a39f5

Please sign in to comment.