Skip to content

Customize naming strategy : TypeError: namingStrategy.tableName  #5286

@karousn

Description

@karousn

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] ^0.2.18 (or put your version here)

Steps to reproduce or a small repository showing the problem:

i am trying to create a custom naming strategy for the columnName:

export class CustomNamingStrategy extends DefaultNamingStrategy implements NamingStrategyInterface {
  columnName(propertyName: string, customName: string, embeddedPrefixes: string[]): string {
    return snakeCase(embeddedPrefixes.concat(customName ? customName : propertyName).join("_"));
  }
}

ormconfig.json

  "namingStrategy": ["src/libs/typeorm/namingStrategy/CustomNamingStrategy.ts"],

inspired by this, i try to change the method by one other exist in the example and i got the same message error.
i got this message error when i save ( i have : "synchronize": true in config file) :
TypeError: namingStrategy.tableName is not a function
The trace :
(node:1465) UnhandledPromiseRejectionWarning: TypeError: namingStrategy.tableName is not a function at EntityMetadata.build (/home/node/app/src/metadata/EntityMetadata.ts:787:58) at /home/node/app/src/metadata-builder/EntityMetadataBuilder.ts:94:55 at Array.forEach (<anonymous>) at EntityMetadataBuilder.build (/home/node/app/src/metadata-builder/EntityMetadataBuilder.ts:94:14) at ConnectionMetadataBuilder.buildEntityMetadatas (/home/node/app/src/connection/ConnectionMetadataBuilder.ts:66:111) at Connection.buildMetadatas (/home/node/app/src/connection/Connection.ts:513:59) at Connection.<anonymous> (/home/node/app/src/connection/Connection.ts:190:18)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions