Skip to content

Commit

Permalink
fix: support multiple JoinColumns in EntitySchema
Browse files Browse the repository at this point in the history
update type definition and schema transformer
so that - like the decorator - the EntitySchema can define
composite `JoinColumn` definitions

Closes: typeorm#5444
  • Loading branch information
imnotjames committed Jul 14, 2020
1 parent 6f6bdbd commit 38706a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/entity-schema/EntitySchemaRelationOptions.ts
Expand Up @@ -55,7 +55,7 @@ export interface EntitySchemaRelationOptions {
/**
* Join column options of this column. If set to true then it simply means that it has a join column.
*/
joinColumn?: boolean|JoinColumnOptions;
joinColumn?: boolean|JoinColumnOptions|JoinColumnOptions[];

/**
* Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.
Expand Down
18 changes: 11 additions & 7 deletions src/entity-schema/EntitySchemaTransformer.ts
Expand Up @@ -151,13 +151,17 @@ export class EntitySchemaTransformer {
};
metadataArgsStorage.joinColumns.push(joinColumn);
} else {
const joinColumn: JoinColumnMetadataArgs = {
target: options.target || options.name,
propertyName: relationName,
name: relationSchema.joinColumn.name,
referencedColumnName: relationSchema.joinColumn.referencedColumnName
};
metadataArgsStorage.joinColumns.push(joinColumn);
const joinColumns = Array.isArray(relationSchema.joinColumn) ? relationSchema.joinColumn : [relationSchema.joinColumn];

for (const column of joinColumns) {
const joinColumn: JoinColumnMetadataArgs = {
target: options.target || options.name,
propertyName: relationName,
name: column.name,
referencedColumnName: column.referencedColumnName
};
metadataArgsStorage.joinColumns.push(joinColumn);
}
}
}

Expand Down

0 comments on commit 38706a7

Please sign in to comment.