@mikro-orm/entity-generator 7.0.0-dev.114 → 7.0.0-dev.116
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/EntityGenerator.js +10 -14
- package/SourceFile.js +6 -6
- package/package.json +4 -4
- package/tsconfig.build.tsbuildinfo +1 -1
package/EntityGenerator.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EntitySchema, ReferenceKind, types, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { DatabaseSchema, } from '@mikro-orm/sql';
|
|
3
3
|
import { fs } from '@mikro-orm/core/fs-utils';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
@@ -215,7 +215,7 @@ export class EntityGenerator {
|
|
|
215
215
|
inverseJoinColumns: meta.relations[1].fieldNames,
|
|
216
216
|
};
|
|
217
217
|
if (outputPurePivotTables || this.referencedEntities.has(meta)) {
|
|
218
|
-
ownerProp.pivotEntity = meta.
|
|
218
|
+
ownerProp.pivotEntity = meta.class;
|
|
219
219
|
}
|
|
220
220
|
if (fixedOrderColumn) {
|
|
221
221
|
ownerProp.fixedOrder = true;
|
|
@@ -279,20 +279,16 @@ export class EntityGenerator {
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
generateAndAttachCustomBaseEntity(metadata, customBaseEntityName) {
|
|
282
|
-
let
|
|
282
|
+
let base = metadata.find(meta => meta.className === customBaseEntityName);
|
|
283
|
+
if (!base) {
|
|
284
|
+
const schema = new EntitySchema({ className: customBaseEntityName, abstract: true });
|
|
285
|
+
base = schema.init().meta;
|
|
286
|
+
metadata.push(base);
|
|
287
|
+
}
|
|
283
288
|
for (const meta of metadata) {
|
|
284
|
-
if (meta.className
|
|
285
|
-
|
|
286
|
-
continue;
|
|
289
|
+
if (meta.className !== customBaseEntityName) {
|
|
290
|
+
meta.extends ??= base.class;
|
|
287
291
|
}
|
|
288
|
-
meta.extends ??= customBaseEntityName;
|
|
289
|
-
}
|
|
290
|
-
if (!baseClassExists) {
|
|
291
|
-
metadata.push(new EntityMetadata({
|
|
292
|
-
className: customBaseEntityName,
|
|
293
|
-
abstract: true,
|
|
294
|
-
relations: [],
|
|
295
|
-
}));
|
|
296
292
|
}
|
|
297
293
|
}
|
|
298
294
|
castNullDefaultsToUndefined(metadata) {
|
package/SourceFile.js
CHANGED
|
@@ -209,8 +209,8 @@ export class SourceFile {
|
|
|
209
209
|
}
|
|
210
210
|
ret += `class ${this.meta.className}`;
|
|
211
211
|
if (this.meta.extends) {
|
|
212
|
-
this.entityImports.add(this.meta.extends);
|
|
213
|
-
ret += ` extends ${this.meta.extends}`;
|
|
212
|
+
this.entityImports.add(Utils.className(this.meta.extends));
|
|
213
|
+
ret += ` extends ${Utils.className(this.meta.extends)}`;
|
|
214
214
|
}
|
|
215
215
|
else if (this.options.useCoreBaseEntity) {
|
|
216
216
|
ret += ` extends ${this.referenceCoreImport('BaseEntity')}`;
|
|
@@ -426,7 +426,7 @@ export class SourceFile {
|
|
|
426
426
|
}
|
|
427
427
|
if (this.meta.discriminatorMap) {
|
|
428
428
|
options.discriminatorMap = Object.fromEntries(Object.entries(this.meta.discriminatorMap)
|
|
429
|
-
.map(([discriminatorValue,
|
|
429
|
+
.map(([discriminatorValue, cls]) => [discriminatorValue, this.quote(Utils.className(cls))]));
|
|
430
430
|
}
|
|
431
431
|
return options;
|
|
432
432
|
}
|
|
@@ -721,9 +721,9 @@ export class SourceFile {
|
|
|
721
721
|
if (prop.pivotTable !== this.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name, this.meta.tableName)) {
|
|
722
722
|
options.pivotTable = this.quote(prop.pivotTable);
|
|
723
723
|
}
|
|
724
|
-
if (prop.pivotEntity && prop.pivotEntity !== prop.pivotTable) {
|
|
725
|
-
this.entityImports.add(prop.pivotEntity);
|
|
726
|
-
options.pivotEntity = `() => ${prop.pivotEntity}`;
|
|
724
|
+
if (prop.pivotEntity && Utils.className(prop.pivotEntity) !== prop.pivotTable) {
|
|
725
|
+
this.entityImports.add(Utils.className(prop.pivotEntity));
|
|
726
|
+
options.pivotEntity = `() => ${Utils.className(prop.pivotEntity)}`;
|
|
727
727
|
}
|
|
728
728
|
if (prop.joinColumns.length === 1) {
|
|
729
729
|
options.joinColumn = this.quote(prop.joinColumns[0]);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/entity-generator",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.116",
|
|
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",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/sql": "7.0.0-dev.
|
|
53
|
+
"@mikro-orm/sql": "7.0.0-dev.116"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@mikro-orm/core": "^6.6.
|
|
56
|
+
"@mikro-orm/core": "^6.6.3"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
59
|
+
"@mikro-orm/core": "7.0.0-dev.116"
|
|
60
60
|
}
|
|
61
61
|
}
|