@mikro-orm/core 7.0.0-dev.147 → 7.0.0-dev.149

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.
@@ -936,8 +936,26 @@ export class MetadataDiscovery {
936
936
  if (rootProp && (rootProp.type !== prop.type || (rootProp.fieldNames && prop.fieldNames && !compareArrays(rootProp.fieldNames, prop.fieldNames)))) {
937
937
  const name = newProp.name;
938
938
  this.initFieldName(newProp, newProp.object);
939
+ newProp.renamedFrom = name;
939
940
  newProp.name = name + '_' + (i++);
940
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 && compareArrays(childMeta.properties[prop.name].fieldNames, rootProp.fieldNames)) {
952
+ rootProp.stiFieldNameMap[discValue] = rootProp.fieldNames[0];
953
+ break;
954
+ }
955
+ }
956
+ }
957
+ rootProp.stiFieldNameMap[meta.discriminatorValue] = prop.fieldNames[0];
958
+ rootProp.stiFieldNames.push(...prop.fieldNames);
941
959
  newProp.nullable = true;
942
960
  newProp.name = name;
943
961
  newProp.hydrate = false;
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.147",
4
+ "version": "7.0.0-dev.149",
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
- if (batched && changeSets.length > 1 && this.config.get('useBatchUpdates', this.platform.usesBatchUpdates())) {
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
- const res = await this.driver.nativeInsertMany(meta.class, [changeSet.payload], options);
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.147';
126
+ static #ORM_VERSION = '7.0.0-dev.149';
127
127
  /**
128
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
129
129
  */