@mikro-orm/core 6.6.5-dev.1 → 6.6.5-dev.3
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.
|
@@ -974,22 +974,42 @@ class MetadataDiscovery {
|
|
|
974
974
|
let i = 1;
|
|
975
975
|
Object.values(meta.properties).forEach(prop => {
|
|
976
976
|
const newProp = { ...prop };
|
|
977
|
-
|
|
977
|
+
const rootProp = meta.root.properties[prop.name];
|
|
978
|
+
if (rootProp && (rootProp.type !== prop.type || (rootProp.fieldNames && prop.fieldNames && !(0, Utils_1.compareArrays)(rootProp.fieldNames, prop.fieldNames)))) {
|
|
978
979
|
const name = newProp.name;
|
|
979
980
|
this.initFieldName(newProp, newProp.object);
|
|
981
|
+
newProp.renamedFrom = name;
|
|
980
982
|
newProp.name = name + '_' + (i++);
|
|
981
983
|
meta.root.addProperty(newProp);
|
|
984
|
+
// Track all field variants and map discriminator values to field names
|
|
985
|
+
if (!rootProp.stiFieldNames) {
|
|
986
|
+
this.initFieldName(prop, prop.object);
|
|
987
|
+
this.initFieldName(rootProp, rootProp.object);
|
|
988
|
+
rootProp.stiFieldNames = [...rootProp.fieldNames];
|
|
989
|
+
rootProp.stiFieldNameMap = {};
|
|
990
|
+
// Find which discriminator owns the original fieldNames
|
|
991
|
+
for (const [discValue, childClass] of Object.entries(meta.root.discriminatorMap)) {
|
|
992
|
+
const childMeta = this.metadata.find(childClass);
|
|
993
|
+
if (childMeta?.properties[prop.name]?.fieldNames &&
|
|
994
|
+
(0, Utils_1.compareArrays)(childMeta.properties[prop.name].fieldNames, rootProp.fieldNames)) {
|
|
995
|
+
rootProp.stiFieldNameMap[discValue] = rootProp.fieldNames[0];
|
|
996
|
+
break;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
rootProp.stiFieldNameMap[meta.discriminatorValue] = prop.fieldNames[0];
|
|
1001
|
+
rootProp.stiFieldNames.push(...prop.fieldNames);
|
|
982
1002
|
newProp.nullable = true;
|
|
983
1003
|
newProp.name = name;
|
|
984
1004
|
newProp.hydrate = false;
|
|
985
1005
|
newProp.inherited = true;
|
|
986
1006
|
return;
|
|
987
1007
|
}
|
|
988
|
-
if (prop.enum && prop.items &&
|
|
989
|
-
newProp.items = Utils_1.Utils.unique([...
|
|
1008
|
+
if (prop.enum && prop.items && rootProp?.items) {
|
|
1009
|
+
newProp.items = Utils_1.Utils.unique([...rootProp.items, ...prop.items]);
|
|
990
1010
|
}
|
|
991
1011
|
newProp.nullable = true;
|
|
992
|
-
newProp.inherited = !
|
|
1012
|
+
newProp.inherited = !rootProp;
|
|
993
1013
|
meta.root.addProperty(newProp);
|
|
994
1014
|
});
|
|
995
1015
|
meta.collection = meta.root.collection;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.6.5-dev.
|
|
3
|
+
"version": "6.6.5-dev.3",
|
|
4
4
|
"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.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.3",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.6.5-dev.
|
|
67
|
+
"mikro-orm": "6.6.5-dev.3",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/typings.d.ts
CHANGED
|
@@ -364,6 +364,9 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
364
364
|
unique?: boolean | string;
|
|
365
365
|
nullable?: boolean;
|
|
366
366
|
inherited?: boolean;
|
|
367
|
+
renamedFrom?: string;
|
|
368
|
+
stiFieldNames?: string[];
|
|
369
|
+
stiFieldNameMap?: Dictionary<string>;
|
|
367
370
|
unsigned?: boolean;
|
|
368
371
|
mapToPk?: boolean;
|
|
369
372
|
persist?: boolean;
|
|
@@ -48,7 +48,10 @@ class ChangeSetPersister {
|
|
|
48
48
|
}
|
|
49
49
|
const meta = this.metadata.find(changeSets[0].name);
|
|
50
50
|
changeSets.forEach(changeSet => this.processProperties(changeSet));
|
|
51
|
-
|
|
51
|
+
// For STI with conflicting fieldNames (renamedFrom properties), we can't batch mixed child types
|
|
52
|
+
const hasSTIConflicts = meta.root.props.some(p => p.renamedFrom);
|
|
53
|
+
const hasMixedTypes = hasSTIConflicts && changeSets.some(cs => cs.meta.class !== meta.class);
|
|
54
|
+
if (batched && changeSets.length > 1 && !hasMixedTypes && this.config.get('useBatchUpdates', this.platform.usesBatchUpdates())) {
|
|
52
55
|
return this.persistManagedEntities(meta, changeSets, options);
|
|
53
56
|
}
|
|
54
57
|
for (const changeSet of changeSets) {
|
|
@@ -96,7 +99,8 @@ class ChangeSetPersister {
|
|
|
96
99
|
options = this.prepareOptions(meta, options, {
|
|
97
100
|
convertCustomTypes: false,
|
|
98
101
|
});
|
|
99
|
-
|
|
102
|
+
// Use changeSet's own meta for STI entities to get correct field mappings
|
|
103
|
+
const res = await this.driver.nativeInsertMany(changeSet.meta.className, [changeSet.payload], options);
|
|
100
104
|
if (!wrapped.hasPrimaryKey()) {
|
|
101
105
|
this.mapPrimaryKey(meta, res.insertId, changeSet);
|
|
102
106
|
}
|