@mikro-orm/core 7.0.8-dev.5 → 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.
@@ -53,6 +53,32 @@ export class EntityLoader {
53
53
  for (const pop of populate) {
54
54
  await this.populateField(entityName, entities, pop, options);
55
55
  }
56
+ // Child-specific relations exist only on child metadata, so the parent-scoped populate loop above skips them (GH #7453).
57
+ if (Array.isArray(populate) &&
58
+ populate.some(p => p.all) &&
59
+ meta.inheritanceType === 'tpt' &&
60
+ meta.tptChildren?.length) {
61
+ const byType = new Map();
62
+ for (const entity of entities) {
63
+ const entityMeta = helper(entity).__meta;
64
+ if (entityMeta !== meta) {
65
+ const group = byType.get(entityMeta);
66
+ if (group) {
67
+ group.push(entity);
68
+ }
69
+ else {
70
+ byType.set(entityMeta, [entity]);
71
+ }
72
+ }
73
+ }
74
+ for (const [childMeta, group] of byType) {
75
+ await this.populate(childMeta.class, group, true, {
76
+ ...options,
77
+ lookup: false,
78
+ validate: false,
79
+ });
80
+ }
81
+ }
56
82
  for (const entity of entities) {
57
83
  visited.delete(entity);
58
84
  }
@@ -711,6 +737,11 @@ export class EntityLoader {
711
737
  all: true,
712
738
  });
713
739
  });
740
+ // For TPT parents with child types, keep an all:true sentinel so the populate
741
+ // loop doesn't exit early and the TPT child relation population can run after it.
742
+ if (ret.length === 0 && meta.inheritanceType === 'tpt' && meta.tptChildren?.length) {
743
+ ret.push({ field: meta.primaryKeys[0], strategy: LoadStrategy.SELECT_IN, all: true });
744
+ }
714
745
  return ret;
715
746
  }
716
747
  getRelationName(meta, prop) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.8-dev.5",
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.5';
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
  */