Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Names of extra columns for specific tree types moved to NamingStrategy #5737

Merged
merged 1 commit into from May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}