@mikro-orm/core 7.0.8-dev.6 → 7.0.8-dev.8
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 +1 -1
- package/unit-of-work/UnitOfWork.js +37 -3
- package/utils/EntityComparator.d.ts +1 -0
- package/utils/EntityComparator.js +12 -9
- package/utils/Utils.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.8-dev.
|
|
3
|
+
"version": "7.0.8-dev.8",
|
|
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",
|
|
@@ -292,7 +292,12 @@ export class UnitOfWork {
|
|
|
292
292
|
cs.type = type;
|
|
293
293
|
}
|
|
294
294
|
this.initIdentifier(entity);
|
|
295
|
-
|
|
295
|
+
if (wrapped.__meta.inheritanceType === 'tpt' && wrapped.__meta.tptParent) {
|
|
296
|
+
this.createTPTChangeSets(entity, cs);
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
this.#changeSets.set(entity, cs);
|
|
300
|
+
}
|
|
296
301
|
this.#persistStack.delete(entity);
|
|
297
302
|
wrapped.__originalEntityData = this.#comparator.prepareEntity(entity);
|
|
298
303
|
}
|
|
@@ -304,8 +309,37 @@ export class UnitOfWork {
|
|
|
304
309
|
}
|
|
305
310
|
const cs = this.#changeSetComputer.computeChangeSet(entity);
|
|
306
311
|
if (cs && !this.checkUniqueProps(cs)) {
|
|
307
|
-
|
|
308
|
-
|
|
312
|
+
const wrapped = helper(entity);
|
|
313
|
+
// For TPT entities, update only each table's own properties so parent
|
|
314
|
+
// columns don't leak into the leaf table's INSERT/UPDATE (GH #7455).
|
|
315
|
+
if (wrapped.__meta.inheritanceType === 'tpt' && wrapped.__meta.tptParent) {
|
|
316
|
+
for (const prop of wrapped.__meta.ownProps) {
|
|
317
|
+
if (prop.name in cs.payload) {
|
|
318
|
+
changeSet.payload[prop.name] = cs.payload[prop.name];
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
changeSet.tptChangeSets ??= [];
|
|
322
|
+
let current = wrapped.__meta.tptParent;
|
|
323
|
+
let idx = 0;
|
|
324
|
+
while (current) {
|
|
325
|
+
let parentCs = changeSet.tptChangeSets.find(pc => pc.meta === current);
|
|
326
|
+
if (!parentCs) {
|
|
327
|
+
parentCs = new ChangeSet(entity, changeSet.type, {}, current);
|
|
328
|
+
changeSet.tptChangeSets.splice(idx, 0, parentCs);
|
|
329
|
+
}
|
|
330
|
+
idx++;
|
|
331
|
+
for (const prop of current.ownProps) {
|
|
332
|
+
if (prop.name in cs.payload) {
|
|
333
|
+
parentCs.payload[prop.name] = cs.payload[prop.name];
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
current = current.tptParent;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
Object.assign(changeSet.payload, cs.payload);
|
|
341
|
+
}
|
|
342
|
+
wrapped.__originalEntityData = this.#comparator.prepareEntity(entity);
|
|
309
343
|
}
|
|
310
344
|
}
|
|
311
345
|
/** Marks an entity for persistence, cascading to related entities. */
|
|
@@ -457,15 +457,7 @@ export class EntityComparator {
|
|
|
457
457
|
else {
|
|
458
458
|
ret += `${padding}if (${nullCond}) {\n`;
|
|
459
459
|
ret +=
|
|
460
|
-
meta.
|
|
461
|
-
.filter(p => p.embedded?.[0] === prop.name &&
|
|
462
|
-
// object for JSON embeddable
|
|
463
|
-
(p.object || p.persist !== false))
|
|
464
|
-
.map(childProp => {
|
|
465
|
-
const childDataKey = meta.embeddable || prop.object ? dataKey + this.wrap(childProp.embedded[1]) : this.wrap(childProp.name);
|
|
466
|
-
return `${padding} ret${childDataKey} = null;`;
|
|
467
|
-
})
|
|
468
|
-
.join('\n') + `\n`;
|
|
460
|
+
this.getInlineEmbeddedNullLines(meta, prop.name, padding, dataKey, !!(meta.embeddable || prop.object)).join('\n') + `\n`;
|
|
469
461
|
ret += `${padding}}\n`;
|
|
470
462
|
}
|
|
471
463
|
const cond = `entity${path.map(k => this.wrap(k)).join('')} != null`;
|
|
@@ -515,6 +507,17 @@ export class EntityComparator {
|
|
|
515
507
|
}
|
|
516
508
|
return `${ret}${padding}}`;
|
|
517
509
|
}
|
|
510
|
+
getInlineEmbeddedNullLines(meta, parentName, padding, dataKey, useEmbeddedKey) {
|
|
511
|
+
return meta.props
|
|
512
|
+
.filter(p => p.embedded?.[0] === parentName && (p.object || p.persist !== false))
|
|
513
|
+
.flatMap(childProp => {
|
|
514
|
+
const childDataKey = useEmbeddedKey ? dataKey + this.wrap(childProp.embedded[1]) : this.wrap(childProp.name);
|
|
515
|
+
if (childProp.kind === ReferenceKind.EMBEDDED && !childProp.object) {
|
|
516
|
+
return this.getInlineEmbeddedNullLines(meta, childProp.name, padding, childDataKey, useEmbeddedKey);
|
|
517
|
+
}
|
|
518
|
+
return [`${padding} ret${childDataKey} = null;`];
|
|
519
|
+
});
|
|
520
|
+
}
|
|
518
521
|
registerCustomType(prop, context) {
|
|
519
522
|
const convertorKey = this.safeKey(prop.name);
|
|
520
523
|
context.set(`convertToDatabaseValue_${convertorKey}`, (val) => {
|
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.8-dev.
|
|
135
|
+
static #ORM_VERSION = '7.0.8-dev.8';
|
|
136
136
|
/**
|
|
137
137
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
138
138
|
*/
|