TypeORM custom naming strategies fail with "TypeError: namingStrategy.tableName is not a function"
See original GitHub issueIssue 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:
- Created 3 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I did a little bit of digging:
I’ve console.logged the value of
connection.namingStrategy
, on theEntityMetadata.ts
file (here).Turns out that the value of this field is:
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.
Same here. Any news on this?