Naming Strategy
When mapping your entities to database tables and columns, their names will be defined by naming strategy. There are 3 basic naming strategies you can choose from:
UnderscoreNamingStrategy
- default of all SQL driversMongoNamingStrategy
- default ofMongoDriver
EntityCaseNamingStrategy
- uses unchanged entity and property names
You can override this when initializing ORM. You can also provide your own naming strategy, just
implement NamingStrategy
interface and provide your implementation when bootstrapping ORM:
You can also extend
AbstractNamingStrategy
which implements one method for you -getClassName()
that is used to map entity file name to class name.
#
Naming Strategy in mongo driverMongoNamingStrategy
will simply use all field names as they are defined. Collection names will
be translated into lower-cased dashed form:
MyCoolEntity
will be translated into my-cool-entity
collection name.
#
Naming Strategy in SQL driversMySqlDriver
defaults to UnderscoreNamingStrategy
, which means your all your database tables and
columns will be lower-cased and words divided by underscored:
#
NamingStrategy APINamingStrategy.getClassName(file: string, separator?: string): string
#
Return a name of the class based on its file name.
NamingStrategy.classToTableName(entityName: string): string
#
Return a table name for an entity class.
NamingStrategy.propertyToColumnName(propertyName: string): string
#
Return a column name for a property.
NamingStrategy.referenceColumnName(): string
#
Return the default reference column name.
NamingStrategy.joinColumnName(propertyName: string): string
#
Return a join column name for a property.
NamingStrategy.joinTableName(sourceEntity: string, targetEntity: string, propertyName?: string): string
#
Return a join table name.
NamingStrategy.joinKeyColumnName(entityName: string, referencedColumnName?: string): string
#
Return the foreign key column name for the given parameters.