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

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.
@@ -228,7 +228,8 @@ export class EntityHelper {
228
228
  // Inverse already points to owner — propagation is not needed,
229
229
  // but we still need to clean up old's inverse side.
230
230
  helper(old).__pk ??= helper(old).getPrimaryKey();
231
- if (old[prop2.name] != null) {
231
+ // Don't nullify the FK if it's part of the PK — the entity will be deleted via orphan removal
232
+ if (old[prop2.name] != null && !(prop.orphanRemoval && prop2.primary)) {
232
233
  delete helper(old).__data[prop2.name];
233
234
  old[prop2.name] = null;
234
235
  }
@@ -267,7 +268,8 @@ export class EntityHelper {
267
268
  else {
268
269
  entity[prop2.name] = Reference.wrapReference(owner, prop);
269
270
  }
270
- if (old?.[prop2.name] != null) {
271
+ // Don't nullify the FK if it's part of the PK — the entity will be deleted via orphan removal
272
+ if (old?.[prop2.name] != null && !(prop.orphanRemoval && prop2.primary)) {
271
273
  delete helper(old).__data[prop2.name];
272
274
  old[prop2.name] = null;
273
275
  }
@@ -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.4",
3
+ "version": "7.0.8-dev.6",
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",
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.4';
135
+ static #ORM_VERSION = '7.0.8-dev.6';
136
136
  /**
137
137
  * Checks if the argument is instance of `Object`. Returns false for arrays.
138
138
  */