Skip to content

Commit

Permalink
fix: fix entityManager.getId for custom join table
Browse files Browse the repository at this point in the history
getId currently returns undefined for an entity with composite primary
key if primary key columns also foreign keys with lazy relations,
for e.g., in a custom join table. This commit tries to fix that

Closes: typeorm#7736 (maybe)
  • Loading branch information
ranjan-purbey committed Feb 21, 2022
1 parent 1f54c70 commit ff3dad7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/metadata/ColumnMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ export class ColumnMetadata {
return Object.keys(map).length > 0 ? map : undefined;

} else { // no embeds - no problems. Simply return column property name and its value of the entity
if (this.relationMetadata && entity[this.relationMetadata.propertyName] && entity[this.relationMetadata.propertyName] instanceof Object) {
if (this.relationMetadata && !Object.getOwnPropertyDescriptor(entity, this.relationMetadata.propertyName)?.get && entity[this.relationMetadata.propertyName] && entity[this.relationMetadata.propertyName] instanceof Object) {
const map = this.relationMetadata.joinColumns.reduce((map, joinColumn) => {
const value = joinColumn.referencedColumn!.getEntityValueMap(entity[this.relationMetadata!.propertyName]);
if (value === undefined) return map;
Expand Down

0 comments on commit ff3dad7

Please sign in to comment.