Skip to content

Commit

Permalink
fix: Child entities not being saved correctly with cascade actions (#…
Browse files Browse the repository at this point in the history
…6219)

* fix: Child entities not being saved correctly with cascade actions

* fixes tslint complains
  • Loading branch information
ZBAGI committed Sep 4, 2020
1 parent 4fc4a1b commit 16a2d80
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/metadata/EntityMetadata.ts
Expand Up @@ -700,14 +700,21 @@ export class EntityMetadata {
relations.forEach(relation => {
const value = relation.getEntityValue(entity);
if (Array.isArray(value)) {
value.forEach(subValue => relationsAndValues.push([relation, subValue, relation.inverseEntityMetadata]));
value.forEach(subValue => relationsAndValues.push([relation, subValue, this.getInverseEntityMetadata(subValue, relation)]));
} else if (value) {
relationsAndValues.push([relation, value, relation.inverseEntityMetadata]);
relationsAndValues.push([relation, value, this.getInverseEntityMetadata(value, relation)]);
}
});
return relationsAndValues;
}

private getInverseEntityMetadata(value: any, relation: RelationMetadata): EntityMetadata {
const childEntityMetadata = relation.inverseEntityMetadata.childEntityMetadatas.find(metadata =>
metadata.target === value.constructor
);
return childEntityMetadata ? childEntityMetadata : relation.inverseEntityMetadata;
}

// -------------------------------------------------------------------------
// Public Static Methods
// -------------------------------------------------------------------------
Expand Down

0 comments on commit 16a2d80

Please sign in to comment.