@mikro-orm/core 6.6.13 → 6.6.14-dev.0

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.
@@ -50,6 +50,7 @@ export declare class MetadataDiscovery {
50
50
  private defineBaseEntityProperties;
51
51
  private initPolyEmbeddables;
52
52
  private initEmbeddables;
53
+ private sameRelationTargetRoot;
53
54
  private initSingleTableInheritance;
54
55
  private createDiscriminatorProperty;
55
56
  private initAutoincrement;
@@ -953,6 +953,16 @@ class MetadataDiscovery {
953
953
  });
954
954
  }
955
955
  }
956
+ sameRelationTargetRoot(rootProp, prop) {
957
+ if (rootProp?.kind !== prop.kind) {
958
+ return false;
959
+ }
960
+ if (prop.kind !== enums_1.ReferenceKind.MANY_TO_ONE && prop.kind !== enums_1.ReferenceKind.ONE_TO_ONE) {
961
+ return false;
962
+ }
963
+ const aRoot = this.metadata.find(prop.type)?.root;
964
+ return aRoot != null && aRoot === this.metadata.find(rootProp.type)?.root;
965
+ }
956
966
  initSingleTableInheritance(meta, metadata) {
957
967
  if (meta.root !== meta && !meta.__processed) {
958
968
  meta.root = metadata.find(m => m.className === meta.root.className);
@@ -984,7 +994,12 @@ class MetadataDiscovery {
984
994
  Object.values(meta.properties).forEach(prop => {
985
995
  const newProp = { ...prop };
986
996
  const rootProp = meta.root.properties[prop.name];
987
- if (rootProp && (rootProp.type !== prop.type || (rootProp.fieldNames && prop.fieldNames && !(0, Utils_1.compareArrays)(rootProp.fieldNames, prop.fieldNames)))) {
997
+ // A child that narrows a relation to a subclass of the root's declared
998
+ // target (same STI hierarchy) shares the FK column with the root; treat
999
+ // that as matching so the rename branch below doesn't run (which would
1000
+ // crash — `targetMeta` is only populated later, in `initRelation`).
1001
+ const narrowedRelationOverride = rootProp != null && rootProp.type !== prop.type && this.sameRelationTargetRoot(rootProp, prop);
1002
+ if (rootProp && !narrowedRelationOverride && (rootProp.type !== prop.type || (rootProp.fieldNames && prop.fieldNames && !(0, Utils_1.compareArrays)(rootProp.fieldNames, prop.fieldNames)))) {
988
1003
  const name = newProp.name;
989
1004
  this.initFieldName(newProp, newProp.object);
990
1005
  newProp.renamedFrom = name;
@@ -1019,6 +1034,12 @@ class MetadataDiscovery {
1019
1034
  }
1020
1035
  newProp.nullable = true;
1021
1036
  newProp.inherited = !rootProp;
1037
+ // For narrowed relation overrides, keep the root's declaration intact so
1038
+ // the full target union (e.g. `Food`) is preserved for populates from the
1039
+ // abstract root — otherwise the last child processed would win.
1040
+ if (narrowedRelationOverride) {
1041
+ return;
1042
+ }
1022
1043
  meta.root.addProperty(newProp);
1023
1044
  });
1024
1045
  meta.collection = meta.root.collection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.6.13",
3
+ "version": "6.6.14-dev.0",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.3.3",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.6.13",
67
+ "mikro-orm": "6.6.14-dev.0",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }