@mikro-orm/core 6.6.12-dev.2 → 6.6.13-dev.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.6.12-dev.2",
3
+ "version": "6.6.13-dev.0",
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.12-dev.2",
67
+ "mikro-orm": "6.6.13-dev.0",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -31,6 +31,12 @@ export declare class ChangeSetPersister {
31
31
  private checkConcurrencyKeys;
32
32
  private persistManagedEntitiesBatch;
33
33
  private mapPrimaryKey;
34
+ /**
35
+ * After INSERT + hydration, sync all EntityIdentifier placeholders in composite PK arrays
36
+ * with the real values now present on the entity. This is needed because `mapPrimaryKey`
37
+ * only handles the first PK column, but any scalar PK in a composite key may be auto-generated.
38
+ */
39
+ private syncCompositeIdentifiers;
34
40
  /**
35
41
  * Sets populate flag to new entities so they are serialized like if they were loaded from the db
36
42
  */
@@ -105,6 +105,7 @@ class ChangeSetPersister {
105
105
  this.mapPrimaryKey(meta, res.insertId, changeSet);
106
106
  }
107
107
  this.mapReturnedValues(changeSet.entity, changeSet.payload, res.row, meta);
108
+ this.syncCompositeIdentifiers(changeSet);
108
109
  this.markAsPopulated(changeSet, meta);
109
110
  wrapped.__initialized = true;
110
111
  wrapped.__managed = true;
@@ -148,6 +149,7 @@ class ChangeSetPersister {
148
149
  if (res.rows) {
149
150
  this.mapReturnedValues(changeSet.entity, changeSet.payload, res.rows[i], meta);
150
151
  }
152
+ this.syncCompositeIdentifiers(changeSet);
151
153
  this.markAsPopulated(changeSet, meta);
152
154
  wrapped.__initialized = true;
153
155
  wrapped.__managed = true;
@@ -223,6 +225,24 @@ class ChangeSetPersister {
223
225
  wrapped.__identifier.setValue(value);
224
226
  }
225
227
  }
228
+ /**
229
+ * After INSERT + hydration, sync all EntityIdentifier placeholders in composite PK arrays
230
+ * with the real values now present on the entity. This is needed because `mapPrimaryKey`
231
+ * only handles the first PK column, but any scalar PK in a composite key may be auto-generated.
232
+ */
233
+ syncCompositeIdentifiers(changeSet) {
234
+ const wrapped = (0, entity_1.helper)(changeSet.entity);
235
+ if (!Array.isArray(wrapped.__identifier)) {
236
+ return;
237
+ }
238
+ const pks = changeSet.meta.getPrimaryProps();
239
+ for (let i = 0; i < pks.length; i++) {
240
+ const ident = wrapped.__identifier[i];
241
+ if (ident instanceof entity_1.EntityIdentifier && pks[i].kind === enums_1.ReferenceKind.SCALAR) {
242
+ ident.setValue(changeSet.entity[pks[i].name]);
243
+ }
244
+ }
245
+ }
226
246
  /**
227
247
  * Sets populate flag to new entities so they are serialized like if they were loaded from the db
228
248
  */
@@ -360,8 +380,8 @@ class ChangeSetPersister {
360
380
  changeSet.payload[prop.name] = value.getValue();
361
381
  return;
362
382
  }
363
- if (Array.isArray(value) && value.every(item => item instanceof entity_1.EntityIdentifier)) {
364
- changeSet.payload[prop.name] = value.map(item => item.getValue());
383
+ if (Array.isArray(value) && value.some(item => item instanceof entity_1.EntityIdentifier)) {
384
+ changeSet.payload[prop.name] = value.map(item => item instanceof entity_1.EntityIdentifier ? item.getValue() : item);
365
385
  return;
366
386
  }
367
387
  if (prop.kind === enums_1.ReferenceKind.MANY_TO_MANY && Array.isArray(value)) {