Skip to content

Commit

Permalink
feat: names of extra columns for specific tree types moved to NamingS…
Browse files Browse the repository at this point in the history
…trategy (#5737)
  • Loading branch information
steerio committed May 16, 2020
1 parent c5a22f5 commit ec3be41
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/metadata-builder/EntityMetadataBuilder.ts
Expand Up @@ -403,6 +403,8 @@ export class EntityMetadataBuilder {
}
}

const { namingStrategy } = this.connection;

// check if tree is used then we need to add extra columns for specific tree types
if (entityMetadata.treeType === "materialized-path") {
entityMetadata.ownColumns.push(new ColumnMetadata({
Expand All @@ -414,7 +416,7 @@ export class EntityMetadataBuilder {
mode: "virtual",
propertyName: "mpath",
options: /*tree.column || */ {
name: "mpath",
name: namingStrategy.materializedPathColumnName,
type: "varchar",
nullable: true,
default: ""
Expand All @@ -423,16 +425,17 @@ export class EntityMetadataBuilder {
}));

} else if (entityMetadata.treeType === "nested-set") {
const { left, right } = namingStrategy.nestedSetColumnNames;
entityMetadata.ownColumns.push(new ColumnMetadata({
connection: this.connection,
entityMetadata: entityMetadata,
nestedSetLeft: true,
args: {
target: entityMetadata.target,
mode: "virtual",
propertyName: "nsleft",
propertyName: left,
options: /*tree.column || */ {
name: "nsleft",
name: left,
type: "integer",
nullable: false,
default: 1
Expand All @@ -446,9 +449,9 @@ export class EntityMetadataBuilder {
args: {
target: entityMetadata.target,
mode: "virtual",
propertyName: "nsright",
propertyName: right,
options: /*tree.column || */ {
name: "nsright",
name: right,
type: "integer",
nullable: false,
default: 2
Expand Down
3 changes: 3 additions & 0 deletions src/naming-strategy/DefaultNamingStrategy.ts
Expand Up @@ -153,4 +153,7 @@ export class DefaultNamingStrategy implements NamingStrategyInterface {
eagerJoinRelationAlias(alias: string, propertyPath: string): string {
return alias + "_" + propertyPath.replace(".", "_");
}

nestedSetColumnNames = { left: "nsleft", right: "nsright" };
materializedPathColumnName = "mpath";
}
10 changes: 10 additions & 0 deletions src/naming-strategy/NamingStrategyInterface.ts
Expand Up @@ -121,4 +121,14 @@ export interface NamingStrategyInterface {
* Gets the name of the alias used for relation joins.
*/
eagerJoinRelationAlias(alias: string, propertyPath: string): string;

/**
* Column names for nested sets.
*/
nestedSetColumnNames: { left: string, right: string };

/**
* Column name for materialized paths.
*/
materializedPathColumnName: string;
}

0 comments on commit ec3be41

Please sign in to comment.