When mapping your entities to database tables and columns, their names will be defined by naming strategy. There are 2 basic naming strategies you can choose from:
UnderscoreNamingStrategy
- default of all SQL driversMongoNamingStrategy
- default ofMongoDriver
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:
class YourCustomNamingStrategy implements NamingStrategy {
...
}
const orm = await MikroORM.init({
...
namingStrategy: YourCustomNamingStrategy,
...
});
You can also extend
AbstractNamingStrategy
which implements one method for you -getClassName()
that is used to map entity file name to class name.
MongoNamingStrategy
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.
MySqlDriver
defaults to UnderscoreNamingStrategy
, which means your all your database tables and
columns will be lower-cased and words divided by underscored:
CREATE TABLE `author` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime(3) DEFAULT NULL,
`updated_at` datetime(3) DEFAULT NULL,
`terms_accepted` tinyint(1) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`born` datetime DEFAULT NULL,
`favourite_book_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Return a name of the class based on its file name.
Return a table name for an entity class.
Return a column name for a property.
Return the default reference column name.
Return a join column name for a property.
NamingStrategy.joinTableName(sourceEntity: string, targetEntity: string, propertyName?: string): string
Return a join table name.
Return the foreign key column name for the given parameters.