question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeORM custom naming strategies fail with "TypeError: namingStrategy.tableName is not a function"

See original GitHub issue

Issue type: [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:

[X] latest [ ] @next [X] 0.2.26, 0.2.27 (or put your version here)

Steps to reproduce or a small repository showing the problem:

Using a custom naming strategy worked fine until 0.2.26. It is still broken in 0.2.27. After upgrading TypeORM to 0.2.26, I receive:

import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
import { Schema } from '@golevelup/profiguration';
import { SnakeNamingStrategy } from 'typeorm-naming-strategies';
import { TypeOrmModuleOptions } from '@nestjs/typeorm';

export type DbConfig = TypeOrmModuleOptions & PostgresConnectionOptions;

export const dbConfigSchema: Schema<DbConfig> = {
  ...
  namingStrategy: new SnakeNamingStrategy(),
  ...
}
TypeError: namingStrategy.tableName is not a function
    at EntityMetadata.build (/Users/paul/code/my-project/node_modules/typeorm/metadata/EntityMetadata.js:492:58)
    at /Users/paul/code/my-project/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:67:72
    at Array.forEach (<anonymous>)
    at EntityMetadataBuilder.build (/Users/paul/code/my-project/node_modules/typeorm/metadata-builder/EntityMetadataBuilder.js:67:14)
    at ConnectionMetadataBuilder.buildEntityMetadatas (/Users/paul/code/my-project/node_modules/typeorm/connection/ConnectionMetadataBuilder.js:58:141)
    at Connection.buildMetadatas (/Users/paul/code/my-project/node_modules/typeorm/connection/Connection.js:515:57)
    at Connection.<anonymous> (/Users/paul/code/my-project/node_modules/typeorm/connection/Connection.js:128:30)
    at step (/Users/paul/code/my-project/node_modules/tslib/tslib.js:141:27)
    at Object.next (/Users/paul/code/my-project/node_modules/tslib/tslib.js:122:57)
    at fulfilled (/Users/paul/code/my-project/node_modules/tslib/tslib.js:112:62)

Related issue in popular community naming strategy:

I believe this may have been introduced during the ltree support improvement.

If I downgrade TypeORM to 0.2.22, the naming strategy works just fine.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
antoinejaussoincommented, Nov 29, 2021

I did a little bit of digging:

I’ve console.logged the value of connection.namingStrategy, on the EntityMetadata.ts file (here).

Turns out that the value of this field is:

{
  nestedSetColumnNames: { left: 'nsleft', right: 'nsright' },
  materializedPathColumnName: 'mpath'
}

Which are the only properties of the Naming Strategy object that are NOT functions.

In other words, something deletes all the functions from the object, somewhere.

Hope that helps.

0reactions
antoinejaussoincommented, Nov 29, 2021

Same here. Any news on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: namingStrategy.tableName is not a function #8
TypeORM custom naming strategies fail with "TypeError: namingStrategy.tableName is not a function" typeorm/typeorm#6804.
Read more >
typeorm-naming-strategies - npm
Custom naming strategies for typeorm. Latest version: 4.1.0, last published: 9 months ago. Start using typeorm-naming-strategies in your ...
Read more >
0.3.7 (2022-06-29) | TypeORM Docs
.save repository method not returning generated uuids for aurora-postgres ... It's really better if user specify custom table name into @Entity decorator.
Read more >
Interface NamingStrategyInterface - typeorm
Interface NamingStrategyInterface. Naming strategy defines how auto-generated names for such things like table name, or table column gonna be generated.
Read more >
typeorm/typeorm - Gitter
@pleerock Do I have to create a custom naming strategy for this? ... I tried with --config src/infrastructure/typeorm/orm-config.js with not success.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found