@mikro-orm/core 7.0.0-dev.146 → 7.0.0-dev.148
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EntityMetadata, } from '../typings.js';
|
|
2
|
-
import { Utils } from '../utils/Utils.js';
|
|
2
|
+
import { compareArrays, Utils } from '../utils/Utils.js';
|
|
3
3
|
import { MetadataValidator } from './MetadataValidator.js';
|
|
4
4
|
import { MetadataProvider } from './MetadataProvider.js';
|
|
5
5
|
import { MetadataStorage } from './MetadataStorage.js';
|
|
@@ -932,22 +932,42 @@ export class MetadataDiscovery {
|
|
|
932
932
|
let i = 1;
|
|
933
933
|
Object.values(meta.properties).forEach(prop => {
|
|
934
934
|
const newProp = { ...prop };
|
|
935
|
-
|
|
935
|
+
const rootProp = meta.root.properties[prop.name];
|
|
936
|
+
if (rootProp && (rootProp.type !== prop.type || (rootProp.fieldNames && prop.fieldNames && !compareArrays(rootProp.fieldNames, prop.fieldNames)))) {
|
|
936
937
|
const name = newProp.name;
|
|
937
938
|
this.initFieldName(newProp, newProp.object);
|
|
939
|
+
newProp.renamedFrom = name;
|
|
938
940
|
newProp.name = name + '_' + (i++);
|
|
939
941
|
meta.root.addProperty(newProp);
|
|
942
|
+
// Track all field variants and map discriminator values to field names
|
|
943
|
+
if (!rootProp.stiFieldNames) {
|
|
944
|
+
this.initFieldName(prop, prop.object);
|
|
945
|
+
this.initFieldName(rootProp, rootProp.object);
|
|
946
|
+
rootProp.stiFieldNames = [...rootProp.fieldNames];
|
|
947
|
+
rootProp.stiFieldNameMap = {};
|
|
948
|
+
// Find which discriminator owns the original fieldNames
|
|
949
|
+
for (const [discValue, childClass] of Object.entries(meta.root.discriminatorMap)) {
|
|
950
|
+
const childMeta = this.metadata.find(childClass);
|
|
951
|
+
if (childMeta?.properties[prop.name]?.fieldNames &&
|
|
952
|
+
compareArrays(childMeta.properties[prop.name].fieldNames, rootProp.fieldNames)) {
|
|
953
|
+
rootProp.stiFieldNameMap[discValue] = rootProp.fieldNames[0];
|
|
954
|
+
break;
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
rootProp.stiFieldNameMap[meta.discriminatorValue] = prop.fieldNames[0];
|
|
959
|
+
rootProp.stiFieldNames.push(...prop.fieldNames);
|
|
940
960
|
newProp.nullable = true;
|
|
941
961
|
newProp.name = name;
|
|
942
962
|
newProp.hydrate = false;
|
|
943
963
|
newProp.inherited = true;
|
|
944
964
|
return;
|
|
945
965
|
}
|
|
946
|
-
if (prop.enum && prop.items &&
|
|
947
|
-
newProp.items = Utils.unique([...
|
|
966
|
+
if (prop.enum && prop.items && rootProp?.items) {
|
|
967
|
+
newProp.items = Utils.unique([...rootProp.items, ...prop.items]);
|
|
948
968
|
}
|
|
949
969
|
newProp.nullable = true;
|
|
950
|
-
newProp.inherited = !
|
|
970
|
+
newProp.inherited = !rootProp;
|
|
951
971
|
meta.root.addProperty(newProp);
|
|
952
972
|
});
|
|
953
973
|
meta.tableName = meta.root.tableName;
|
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.148",
|
|
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/typings.d.ts
CHANGED
|
@@ -373,6 +373,9 @@ export interface EntityProperty<Owner = any, Target = any> {
|
|
|
373
373
|
unique?: boolean | string;
|
|
374
374
|
nullable?: boolean;
|
|
375
375
|
inherited?: boolean;
|
|
376
|
+
renamedFrom?: string;
|
|
377
|
+
stiFieldNames?: string[];
|
|
378
|
+
stiFieldNameMap?: Dictionary<string>;
|
|
376
379
|
unsigned?: boolean;
|
|
377
380
|
mapToPk?: boolean;
|
|
378
381
|
persist?: boolean;
|
|
@@ -45,7 +45,10 @@ export class ChangeSetPersister {
|
|
|
45
45
|
}
|
|
46
46
|
const meta = changeSets[0].meta;
|
|
47
47
|
changeSets.forEach(changeSet => this.processProperties(changeSet));
|
|
48
|
-
|
|
48
|
+
// For STI with conflicting fieldNames (renamedFrom properties), we can't batch mixed child types
|
|
49
|
+
const hasSTIConflicts = meta.root.props.some(p => p.renamedFrom);
|
|
50
|
+
const hasMixedTypes = hasSTIConflicts && changeSets.some(cs => cs.meta.class !== meta.class);
|
|
51
|
+
if (batched && changeSets.length > 1 && !hasMixedTypes && this.config.get('useBatchUpdates', this.platform.usesBatchUpdates())) {
|
|
49
52
|
return this.persistManagedEntities(meta, changeSets, options);
|
|
50
53
|
}
|
|
51
54
|
for (const changeSet of changeSets) {
|
|
@@ -112,7 +115,8 @@ export class ChangeSetPersister {
|
|
|
112
115
|
options = this.prepareOptions(meta, options, {
|
|
113
116
|
convertCustomTypes: false,
|
|
114
117
|
});
|
|
115
|
-
|
|
118
|
+
// Use changeSet's own meta for STI entities to get correct field mappings
|
|
119
|
+
const res = await this.driver.nativeInsertMany(changeSet.meta.class, [changeSet.payload], options);
|
|
116
120
|
if (!wrapped.hasPrimaryKey()) {
|
|
117
121
|
this.mapPrimaryKey(meta, res.insertId, changeSet);
|
|
118
122
|
}
|
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.148';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|