@mikro-orm/core 7.0.8-dev.6 → 7.0.8-dev.7

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.8-dev.6",
3
+ "version": "7.0.8-dev.7",
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
- this.#changeSets.set(entity, cs);
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
- Object.assign(changeSet.payload, cs.payload);
308
- helper(entity).__originalEntityData = this.#comparator.prepareEntity(entity);
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. */
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.6';
135
+ static #ORM_VERSION = '7.0.8-dev.7';
136
136
  /**
137
137
  * Checks if the argument is instance of `Object`. Returns false for arrays.
138
138
  */