@mikro-orm/core 7.0.11-dev.13 → 7.0.11-dev.14

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.
@@ -555,7 +555,12 @@ export class EntityLoader {
555
555
  };
556
556
  if (prop.polymorphic && prop.polymorphTargets) {
557
557
  await Promise.all(prop.polymorphTargets.map(async (targetMeta) => {
558
- const targetChildren = unique.filter(child => helper(child).__meta.className === targetMeta.className);
558
+ const targetChildren = unique.filter(child => {
559
+ const childMeta = helper(child).__meta;
560
+ // Use root.className for TPT entities: a Dog (root: Animal) should match
561
+ // targetMeta Animal. For non-TPT entities, root === self.
562
+ return childMeta.root.className === targetMeta.root.className;
563
+ });
559
564
  if (targetChildren.length > 0) {
560
565
  await populateChildren(targetMeta, targetChildren);
561
566
  }
@@ -283,8 +283,10 @@ export class MetadataValidator {
283
283
  validateIndexes(meta, indexes, type) {
284
284
  for (const index of indexes) {
285
285
  for (const propName of Utils.asArray(index.properties)) {
286
- const prop = meta.root.properties[propName];
287
- if (!prop && !Object.values(meta.root.properties).some(p => propName.startsWith(p.name + '.'))) {
286
+ const prop = meta.properties[propName] ?? meta.root.properties[propName];
287
+ if (!prop &&
288
+ !Object.values(meta.properties).some(p => propName.startsWith(p.name + '.')) &&
289
+ !Object.values(meta.root.properties).some(p => propName.startsWith(p.name + '.'))) {
288
290
  throw MetadataError.unknownIndexProperty(meta, propName, type);
289
291
  }
290
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.11-dev.13",
3
+ "version": "7.0.11-dev.14",
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",
@@ -569,7 +569,14 @@ export class EntityComparator {
569
569
  ret += ` ret${dataKey} = null;\n`;
570
570
  ret += ` } else if (typeof entity${entityKey} !== 'undefined') {\n`;
571
571
  ret += ` const val${level} = entity${entityKey}${unwrap};\n`;
572
- ret += ` const discriminator = ${discriminatorMapKey}.get(val${level}?.constructor);\n`;
572
+ // walk up the prototype chain so TPT subclasses resolve to their root's discriminator
573
+ ret += ` let __cls${level} = val${level}?.constructor;\n`;
574
+ ret += ` let discriminator;\n`;
575
+ ret += ` while (__cls${level} != null) {\n`;
576
+ ret += ` discriminator = ${discriminatorMapKey}.get(__cls${level});\n`;
577
+ ret += ` if (discriminator !== undefined) break;\n`;
578
+ ret += ` __cls${level} = Object.getPrototypeOf(__cls${level});\n`;
579
+ ret += ` }\n`;
573
580
  ret += ` const pk = val${level}?.__helper?.__identifier && !val${level}?.__helper?.hasPrimaryKey()\n`;
574
581
  ret += ` ? val${level}.__helper.__identifier\n`;
575
582
  ret += ` : toArray(val${level}?.__helper?.getPrimaryKey(true));\n`;
@@ -8,6 +8,7 @@ export declare class QueryHelper {
8
8
  static readonly SUPPORTED_OPERATORS: string[];
9
9
  /**
10
10
  * Finds the discriminator value (key) for a given entity class in a discriminator map.
11
+ * Walks up the prototype chain so TPT subclasses resolve to their root's key.
11
12
  */
12
13
  static findDiscriminatorValue<T>(discriminatorMap: Dictionary<T>, targetClass: T): string | undefined;
13
14
  static processParams(params: unknown): any;
@@ -9,9 +9,19 @@ export class QueryHelper {
9
9
  static SUPPORTED_OPERATORS = ['>', '<', '<=', '>=', '!', '!='];
10
10
  /**
11
11
  * Finds the discriminator value (key) for a given entity class in a discriminator map.
12
+ * Walks up the prototype chain so TPT subclasses resolve to their root's key.
12
13
  */
13
14
  static findDiscriminatorValue(discriminatorMap, targetClass) {
14
- return Object.entries(discriminatorMap).find(([, cls]) => cls === targetClass)?.[0];
15
+ const entries = Object.entries(discriminatorMap);
16
+ let current = targetClass;
17
+ while (current != null) {
18
+ const hit = entries.find(([, cls]) => cls === current)?.[0];
19
+ if (hit) {
20
+ return hit;
21
+ }
22
+ current = Object.getPrototypeOf(current);
23
+ }
24
+ return undefined;
15
25
  }
16
26
  static processParams(params) {
17
27
  if (Reference.isReference(params)) {
package/utils/Utils.js CHANGED
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
141
141
  /** Collection of general-purpose utility methods used throughout the ORM. */
142
142
  export class Utils {
143
143
  static PK_SEPARATOR = '~~~';
144
- static #ORM_VERSION = '7.0.11-dev.13';
144
+ static #ORM_VERSION = '7.0.11-dev.14';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */