@mikro-orm/core 6.6.5-dev.2 → 6.6.5-dev.4

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.
@@ -978,8 +978,27 @@ class MetadataDiscovery {
978
978
  if (rootProp && (rootProp.type !== prop.type || (rootProp.fieldNames && prop.fieldNames && !(0, Utils_1.compareArrays)(rootProp.fieldNames, prop.fieldNames)))) {
979
979
  const name = newProp.name;
980
980
  this.initFieldName(newProp, newProp.object);
981
+ newProp.renamedFrom = name;
981
982
  newProp.name = name + '_' + (i++);
982
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);
983
1002
  newProp.nullable = true;
984
1003
  newProp.name = name;
985
1004
  newProp.hydrate = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.6.5-dev.2",
3
+ "version": "6.6.5-dev.4",
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.2",
67
+ "mikro-orm": "6.6.5-dev.4",
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
- if (batched && changeSets.length > 1 && this.config.get('useBatchUpdates', this.platform.usesBatchUpdates())) {
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
- const res = await this.driver.nativeInsertMany(meta.className, [changeSet.payload], options);
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
  }
package/utils/Utils.js CHANGED
@@ -658,7 +658,7 @@ class Utils {
658
658
  */
659
659
  static detectTsNode() {
660
660
  /* istanbul ignore next */
661
- return process.argv[0].endsWith('ts-node') // running via ts-node directly
661
+ return process.argv[0]?.endsWith('ts-node') // running via ts-node directly
662
662
  // @ts-ignore
663
663
  || !!process[Symbol.for('ts-node.register.instance')] // check if internal ts-node symbol exists
664
664
  || !!process.env.TS_JEST // check if ts-jest is used (works only with v27.0.4+)