@mikro-orm/core 7.0.0-dev.111 → 7.0.0-dev.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/metadata/EntitySchema.js +1 -5
- package/metadata/MetadataDiscovery.js +8 -8
- package/naming-strategy/AbstractNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/package.json +1 -1
- package/utils/Utils.js +1 -1
package/metadata/EntitySchema.js
CHANGED
|
@@ -21,10 +21,6 @@ export class EntitySchema {
|
|
|
21
21
|
if (meta.class && !meta.internal) {
|
|
22
22
|
EntitySchema.REGISTRY.set(meta.class, this);
|
|
23
23
|
}
|
|
24
|
-
if (meta.tableName || meta.collection) {
|
|
25
|
-
Utils.renameKey(meta, 'tableName', 'collection');
|
|
26
|
-
meta.tableName = meta.collection;
|
|
27
|
-
}
|
|
28
24
|
Object.assign(this._meta, { className: meta.name }, meta);
|
|
29
25
|
this._meta.root ??= this._meta;
|
|
30
26
|
}
|
|
@@ -197,7 +193,7 @@ export class EntitySchema {
|
|
|
197
193
|
const tableName = this._meta.collection ?? this._meta.tableName;
|
|
198
194
|
if (tableName?.includes('.') && !this._meta.schema) {
|
|
199
195
|
this._meta.schema = tableName.substring(0, tableName.indexOf('.'));
|
|
200
|
-
this._meta.
|
|
196
|
+
this._meta.tableName = tableName.substring(tableName.indexOf('.') + 1);
|
|
201
197
|
}
|
|
202
198
|
this.initProperties();
|
|
203
199
|
this.initPrimaryKeys();
|
|
@@ -296,9 +296,9 @@ export class MetadataDiscovery {
|
|
|
296
296
|
}
|
|
297
297
|
// if the definition is using EntitySchema we still want it to go through the metadata provider to validate no types are missing
|
|
298
298
|
this.metadataProvider.loadEntityMetadata(meta);
|
|
299
|
-
if (!meta.
|
|
299
|
+
if (!meta.tableName && meta.name) {
|
|
300
300
|
const entityName = root.discriminatorColumn ? root.name : meta.name;
|
|
301
|
-
meta.
|
|
301
|
+
meta.tableName = this.namingStrategy.classToTableName(entityName);
|
|
302
302
|
}
|
|
303
303
|
this.metadataProvider.saveToCache(meta);
|
|
304
304
|
meta.root = root;
|
|
@@ -404,7 +404,7 @@ export class MetadataDiscovery {
|
|
|
404
404
|
prop.inverseJoinColumns ??= second.fieldNames;
|
|
405
405
|
}
|
|
406
406
|
if (!prop.pivotTable && prop.owner && this.platform.usesPivotTable()) {
|
|
407
|
-
prop.pivotTable = this.namingStrategy.joinTableName(meta.
|
|
407
|
+
prop.pivotTable = this.namingStrategy.joinTableName(meta.className, meta2.tableName, prop.name, meta.tableName);
|
|
408
408
|
}
|
|
409
409
|
if (prop.mappedBy) {
|
|
410
410
|
const prop2 = meta2.properties[prop.mappedBy];
|
|
@@ -417,13 +417,13 @@ export class MetadataDiscovery {
|
|
|
417
417
|
prop.inverseJoinColumns = prop2.joinColumns;
|
|
418
418
|
}
|
|
419
419
|
prop.referencedColumnNames ??= Utils.flatten(meta.primaryKeys.map(primaryKey => meta.properties[primaryKey].fieldNames));
|
|
420
|
-
prop.joinColumns ??= prop.referencedColumnNames.map(referencedColumnName => this.namingStrategy.joinKeyColumnName(meta.root.className, referencedColumnName, meta.compositePK));
|
|
420
|
+
prop.joinColumns ??= prop.referencedColumnNames.map(referencedColumnName => this.namingStrategy.joinKeyColumnName(meta.root.className, referencedColumnName, meta.compositePK, meta.root.tableName));
|
|
421
421
|
prop.inverseJoinColumns ??= this.initManyToOneFieldName(prop, meta2.root.className);
|
|
422
422
|
}
|
|
423
423
|
initManyToOneFields(prop) {
|
|
424
424
|
const meta2 = this.metadata.get(prop.type);
|
|
425
425
|
const fieldNames = Utils.flatten(meta2.primaryKeys.map(primaryKey => meta2.properties[primaryKey].fieldNames));
|
|
426
|
-
Utils.defaultValue(prop, 'referencedTableName', meta2.
|
|
426
|
+
Utils.defaultValue(prop, 'referencedTableName', meta2.tableName);
|
|
427
427
|
if (!prop.joinColumns) {
|
|
428
428
|
prop.joinColumns = fieldNames.map(fieldName => this.namingStrategy.joinKeyColumnName(prop.name, fieldName, fieldNames.length > 1));
|
|
429
429
|
}
|
|
@@ -573,8 +573,8 @@ export class MetadataDiscovery {
|
|
|
573
573
|
}
|
|
574
574
|
// handle self-referenced m:n with same default field names
|
|
575
575
|
if (meta.className === targetType && prop.joinColumns.every((joinColumn, idx) => joinColumn === prop.inverseJoinColumns[idx])) {
|
|
576
|
-
prop.joinColumns = prop.referencedColumnNames.map(name => this.namingStrategy.joinKeyColumnName(meta.
|
|
577
|
-
prop.inverseJoinColumns = prop.referencedColumnNames.map(name => this.namingStrategy.joinKeyColumnName(meta.
|
|
576
|
+
prop.joinColumns = prop.referencedColumnNames.map(name => this.namingStrategy.joinKeyColumnName(meta.tableName + '_1', name, meta.compositePK));
|
|
577
|
+
prop.inverseJoinColumns = prop.referencedColumnNames.map(name => this.namingStrategy.joinKeyColumnName(meta.tableName + '_2', name, meta.compositePK));
|
|
578
578
|
if (prop.inversedBy) {
|
|
579
579
|
const prop2 = this.metadata.get(targetType).properties[prop.inversedBy];
|
|
580
580
|
prop2.inverseJoinColumns = prop.joinColumns;
|
|
@@ -916,7 +916,7 @@ export class MetadataDiscovery {
|
|
|
916
916
|
newProp.inherited = !meta.root.properties[prop.name];
|
|
917
917
|
meta.root.addProperty(newProp);
|
|
918
918
|
});
|
|
919
|
-
meta.
|
|
919
|
+
meta.tableName = meta.root.tableName;
|
|
920
920
|
meta.root.indexes = Utils.unique([...meta.root.indexes, ...meta.indexes]);
|
|
921
921
|
meta.root.uniques = Utils.unique([...meta.root.uniques, ...meta.uniques]);
|
|
922
922
|
meta.root.checks = Utils.unique([...meta.root.checks, ...meta.checks]);
|
|
@@ -26,10 +26,10 @@ export declare abstract class AbstractNamingStrategy implements NamingStrategy {
|
|
|
26
26
|
* @inheritDoc
|
|
27
27
|
*/
|
|
28
28
|
inverseSideName(entityName: string, propertyName: string, kind: ReferenceKind): string;
|
|
29
|
-
abstract classToTableName(entityName: string): string;
|
|
29
|
+
abstract classToTableName(entityName: string, tableName?: string): string;
|
|
30
30
|
abstract joinColumnName(propertyName: string): string;
|
|
31
|
-
abstract joinKeyColumnName(entityName: string, referencedColumnName?: string): string;
|
|
32
|
-
abstract joinTableName(sourceEntity: string, targetEntity: string, propertyName?: string): string;
|
|
31
|
+
abstract joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
|
|
32
|
+
abstract joinTableName(sourceEntity: string, targetEntity: string, propertyName?: string, tableName?: string): string;
|
|
33
33
|
abstract propertyToColumnName(propertyName: string, object?: boolean): string;
|
|
34
34
|
abstract referenceColumnName(): string;
|
|
35
35
|
}
|
|
@@ -3,10 +3,10 @@ import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
|
3
3
|
* This strategy keeps original entity/property names for table/column.
|
|
4
4
|
*/
|
|
5
5
|
export declare class EntityCaseNamingStrategy extends AbstractNamingStrategy {
|
|
6
|
-
classToTableName(entityName: string): string;
|
|
6
|
+
classToTableName(entityName: string, tableName?: string): string;
|
|
7
7
|
joinColumnName(propertyName: string): string;
|
|
8
|
-
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean): string;
|
|
9
|
-
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string): string;
|
|
8
|
+
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
|
|
9
|
+
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string, tableName?: string): string;
|
|
10
10
|
propertyToColumnName(propertyName: string): string;
|
|
11
11
|
referenceColumnName(): string;
|
|
12
12
|
}
|
|
@@ -3,21 +3,22 @@ import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
|
3
3
|
* This strategy keeps original entity/property names for table/column.
|
|
4
4
|
*/
|
|
5
5
|
export class EntityCaseNamingStrategy extends AbstractNamingStrategy {
|
|
6
|
-
classToTableName(entityName) {
|
|
7
|
-
return entityName;
|
|
6
|
+
classToTableName(entityName, tableName) {
|
|
7
|
+
return tableName ?? entityName;
|
|
8
8
|
}
|
|
9
9
|
joinColumnName(propertyName) {
|
|
10
10
|
return propertyName;
|
|
11
11
|
}
|
|
12
|
-
joinKeyColumnName(entityName, referencedColumnName, composite
|
|
12
|
+
joinKeyColumnName(entityName, referencedColumnName, composite, tableName) {
|
|
13
|
+
entityName = this.classToTableName(entityName, tableName);
|
|
13
14
|
const name = entityName.substr(0, 1).toLowerCase() + entityName.substr(1);
|
|
14
15
|
if (composite && referencedColumnName) {
|
|
15
16
|
return name + '_' + referencedColumnName;
|
|
16
17
|
}
|
|
17
18
|
return name;
|
|
18
19
|
}
|
|
19
|
-
joinTableName(sourceEntity, targetEntity, propertyName) {
|
|
20
|
-
return this.classToTableName(sourceEntity) + '_' + this.propertyToColumnName(propertyName);
|
|
20
|
+
joinTableName(sourceEntity, targetEntity, propertyName, tableName) {
|
|
21
|
+
return this.classToTableName(sourceEntity, tableName) + '_' + this.propertyToColumnName(propertyName);
|
|
21
22
|
}
|
|
22
23
|
propertyToColumnName(propertyName) {
|
|
23
24
|
return propertyName;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
2
|
export declare class MongoNamingStrategy extends AbstractNamingStrategy {
|
|
3
|
-
classToTableName(entityName: string): string;
|
|
3
|
+
classToTableName(entityName: string, tableName?: string): string;
|
|
4
4
|
joinColumnName(propertyName: string): string;
|
|
5
|
-
joinKeyColumnName(entityName: string, referencedColumnName?: string): string;
|
|
6
|
-
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string): string;
|
|
5
|
+
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
|
|
6
|
+
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string, tableName?: string): string;
|
|
7
7
|
propertyToColumnName(propertyName: string): string;
|
|
8
8
|
referenceColumnName(): string;
|
|
9
9
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
2
|
export class MongoNamingStrategy extends AbstractNamingStrategy {
|
|
3
|
-
classToTableName(entityName) {
|
|
4
|
-
return entityName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
3
|
+
classToTableName(entityName, tableName) {
|
|
4
|
+
return tableName ?? entityName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
5
5
|
}
|
|
6
6
|
joinColumnName(propertyName) {
|
|
7
7
|
return propertyName;
|
|
8
8
|
}
|
|
9
|
-
joinKeyColumnName(entityName, referencedColumnName) {
|
|
10
|
-
return entityName;
|
|
9
|
+
joinKeyColumnName(entityName, referencedColumnName, composite, tableName) {
|
|
10
|
+
return tableName ?? entityName;
|
|
11
11
|
}
|
|
12
|
-
joinTableName(sourceEntity, targetEntity, propertyName) {
|
|
13
|
-
return this.classToTableName(sourceEntity) + '_' + this.propertyToColumnName(propertyName);
|
|
12
|
+
joinTableName(sourceEntity, targetEntity, propertyName, tableName) {
|
|
13
|
+
return this.classToTableName(sourceEntity, tableName) + '_' + this.propertyToColumnName(propertyName);
|
|
14
14
|
}
|
|
15
15
|
propertyToColumnName(propertyName) {
|
|
16
16
|
return propertyName;
|
|
@@ -7,7 +7,7 @@ export interface NamingStrategy {
|
|
|
7
7
|
/**
|
|
8
8
|
* Return a table name for an entity class
|
|
9
9
|
*/
|
|
10
|
-
classToTableName(entityName: string): string;
|
|
10
|
+
classToTableName(entityName: string, tableName?: string): string;
|
|
11
11
|
/**
|
|
12
12
|
* Return a migration name. This name should allow ordering.
|
|
13
13
|
*/
|
|
@@ -67,11 +67,11 @@ export interface NamingStrategy {
|
|
|
67
67
|
/**
|
|
68
68
|
* Return a join table name
|
|
69
69
|
*/
|
|
70
|
-
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string): string;
|
|
70
|
+
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string, tableName?: string): string;
|
|
71
71
|
/**
|
|
72
72
|
* Return the foreign key column name for the given parameters
|
|
73
73
|
*/
|
|
74
|
-
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean): string;
|
|
74
|
+
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
|
|
75
75
|
/**
|
|
76
76
|
* Returns key/constraint name for the given type. Some drivers might not support all the types (e.g. mysql and sqlite enforce the PK name).
|
|
77
77
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
2
|
export declare class UnderscoreNamingStrategy extends AbstractNamingStrategy {
|
|
3
|
-
classToTableName(entityName: string): string;
|
|
3
|
+
classToTableName(entityName: string, tableName?: string): string;
|
|
4
4
|
joinColumnName(propertyName: string): string;
|
|
5
|
-
joinKeyColumnName(entityName: string, referencedColumnName?: string): string;
|
|
6
|
-
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string): string;
|
|
5
|
+
joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean, tableName?: string): string;
|
|
6
|
+
joinTableName(sourceEntity: string, targetEntity: string, propertyName: string, tableName?: string): string;
|
|
7
7
|
propertyToColumnName(propertyName: string, object?: boolean): string;
|
|
8
8
|
referenceColumnName(): string;
|
|
9
9
|
private underscore;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
|
|
2
2
|
export class UnderscoreNamingStrategy extends AbstractNamingStrategy {
|
|
3
|
-
classToTableName(entityName) {
|
|
4
|
-
return this.underscore(entityName);
|
|
3
|
+
classToTableName(entityName, tableName) {
|
|
4
|
+
return tableName ?? this.underscore(entityName);
|
|
5
5
|
}
|
|
6
6
|
joinColumnName(propertyName) {
|
|
7
7
|
return this.underscore(propertyName) + '_' + this.referenceColumnName();
|
|
8
8
|
}
|
|
9
|
-
joinKeyColumnName(entityName, referencedColumnName) {
|
|
10
|
-
return this.classToTableName(entityName) + '_' + (referencedColumnName || this.referenceColumnName());
|
|
9
|
+
joinKeyColumnName(entityName, referencedColumnName, composite, tableName) {
|
|
10
|
+
return this.classToTableName(entityName, tableName) + '_' + (referencedColumnName || this.referenceColumnName());
|
|
11
11
|
}
|
|
12
|
-
joinTableName(sourceEntity, targetEntity, propertyName) {
|
|
13
|
-
return this.classToTableName(sourceEntity) + '_' + this.classToTableName(propertyName);
|
|
12
|
+
joinTableName(sourceEntity, targetEntity, propertyName, tableName) {
|
|
13
|
+
return this.classToTableName(sourceEntity, tableName) + '_' + this.classToTableName(propertyName);
|
|
14
14
|
}
|
|
15
15
|
propertyToColumnName(propertyName, object) {
|
|
16
16
|
return this.underscore(propertyName);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.112",
|
|
5
5
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
package/utils/Utils.js
CHANGED
|
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
|
|
|
123
123
|
}
|
|
124
124
|
export class Utils {
|
|
125
125
|
static PK_SEPARATOR = '~~~';
|
|
126
|
-
static #ORM_VERSION = '7.0.0-dev.
|
|
126
|
+
static #ORM_VERSION = '7.0.0-dev.112';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|