@mikro-orm/core 7.0.9-dev.2 → 7.0.9-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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.9-dev.
|
|
3
|
+
"version": "7.0.9-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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -24,6 +24,12 @@ export declare class ChangeSetPersister {
|
|
|
24
24
|
private checkConcurrencyKeys;
|
|
25
25
|
private persistManagedEntitiesBatch;
|
|
26
26
|
private mapPrimaryKey;
|
|
27
|
+
/**
|
|
28
|
+
* After INSERT + hydration, sync all EntityIdentifier placeholders in composite PK arrays
|
|
29
|
+
* with the real values now present on the entity. This is needed because `mapPrimaryKey`
|
|
30
|
+
* only handles the first PK column, but any scalar PK in a composite key may be auto-generated.
|
|
31
|
+
*/
|
|
32
|
+
private syncCompositeIdentifiers;
|
|
27
33
|
/**
|
|
28
34
|
* Sets populate flag to new entities so they are serialized like if they were loaded from the db
|
|
29
35
|
*/
|
|
@@ -132,6 +132,7 @@ export class ChangeSetPersister {
|
|
|
132
132
|
this.mapPrimaryKey(meta, res.insertId ?? res.row?.[meta.primaryKeys[0]], changeSet);
|
|
133
133
|
}
|
|
134
134
|
this.mapReturnedValues(changeSet.entity, changeSet.payload, res.row, meta);
|
|
135
|
+
this.syncCompositeIdentifiers(changeSet);
|
|
135
136
|
this.markAsPopulated(changeSet, meta);
|
|
136
137
|
wrapped.__initialized = true;
|
|
137
138
|
wrapped.__managed = true;
|
|
@@ -178,6 +179,7 @@ export class ChangeSetPersister {
|
|
|
178
179
|
if (res.rows) {
|
|
179
180
|
this.mapReturnedValues(changeSet.entity, changeSet.payload, res.rows[i], meta);
|
|
180
181
|
}
|
|
182
|
+
this.syncCompositeIdentifiers(changeSet);
|
|
181
183
|
this.markAsPopulated(changeSet, meta);
|
|
182
184
|
wrapped.__initialized = true;
|
|
183
185
|
wrapped.__managed = true;
|
|
@@ -255,6 +257,24 @@ export class ChangeSetPersister {
|
|
|
255
257
|
wrapped.__identifier.setValue(value);
|
|
256
258
|
}
|
|
257
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* After INSERT + hydration, sync all EntityIdentifier placeholders in composite PK arrays
|
|
262
|
+
* with the real values now present on the entity. This is needed because `mapPrimaryKey`
|
|
263
|
+
* only handles the first PK column, but any scalar PK in a composite key may be auto-generated.
|
|
264
|
+
*/
|
|
265
|
+
syncCompositeIdentifiers(changeSet) {
|
|
266
|
+
const wrapped = helper(changeSet.entity);
|
|
267
|
+
if (!Array.isArray(wrapped.__identifier)) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const pks = changeSet.meta.getPrimaryProps();
|
|
271
|
+
for (let i = 0; i < pks.length; i++) {
|
|
272
|
+
const ident = wrapped.__identifier[i];
|
|
273
|
+
if (ident instanceof EntityIdentifier && pks[i].kind === ReferenceKind.SCALAR) {
|
|
274
|
+
ident.setValue(changeSet.entity[pks[i].name]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
258
278
|
/**
|
|
259
279
|
* Sets populate flag to new entities so they are serialized like if they were loaded from the db
|
|
260
280
|
*/
|
|
@@ -413,8 +433,8 @@ export class ChangeSetPersister {
|
|
|
413
433
|
}
|
|
414
434
|
return;
|
|
415
435
|
}
|
|
416
|
-
if (Array.isArray(value) && value.
|
|
417
|
-
changeSet.payload[prop.name] = value.map(item => item.getValue());
|
|
436
|
+
if (Array.isArray(value) && value.some(item => item instanceof EntityIdentifier)) {
|
|
437
|
+
changeSet.payload[prop.name] = value.map(item => (item instanceof EntityIdentifier ? item.getValue() : item));
|
|
418
438
|
return;
|
|
419
439
|
}
|
|
420
440
|
if (prop.kind === ReferenceKind.MANY_TO_MANY && Array.isArray(value)) {
|
package/utils/Utils.js
CHANGED
|
@@ -132,7 +132,7 @@ export function parseJsonSafe(value) {
|
|
|
132
132
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
133
133
|
export class Utils {
|
|
134
134
|
static PK_SEPARATOR = '~~~';
|
|
135
|
-
static #ORM_VERSION = '7.0.9-dev.
|
|
135
|
+
static #ORM_VERSION = '7.0.9-dev.4';
|
|
136
136
|
/**
|
|
137
137
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
138
138
|
*/
|