@mikro-orm/core 7.0.12-dev.2 → 7.0.12-dev.4

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.12-dev.2",
3
+ "version": "7.0.12-dev.4",
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",
@@ -38,6 +38,11 @@ export declare class QueryHelper {
38
38
  * Handles shared FK columns (e.g., tenant_id referenced by multiple FKs) correctly.
39
39
  */
40
40
  private static extractJoinColumnValues;
41
+ /**
42
+ * Expands a polymorphic entity reference to `[discriminatorValue, ...joinColumnValues]`,
43
+ * matching the column order of `prop.fieldNames`.
44
+ */
45
+ private static extractPolymorphicJoinColumnValues;
41
46
  /**
42
47
  * Extracts the value for a specific column from an entity by finding which PK property
43
48
  * owns that column and recursively traversing FK references.
@@ -327,18 +327,29 @@ export class QueryHelper {
327
327
  continue;
328
328
  }
329
329
  const prop = meta.properties[k];
330
- if (!prop?.joinColumns || prop.joinColumns.length <= 1) {
330
+ const polymorphic = !!prop?.polymorphic && (prop.fieldNames?.length ?? 0) > 1;
331
+ const composite = (prop?.joinColumns?.length ?? 0) > 1;
332
+ if (!polymorphic && !composite) {
331
333
  continue;
332
334
  }
335
+ const expand = (entity) => polymorphic
336
+ ? this.extractPolymorphicJoinColumnValues(entity, prop)
337
+ : this.extractJoinColumnValues(entity, prop);
338
+ const expandItem = (item) => {
339
+ const entity = Reference.isReference(item) ? item.unwrap() : item;
340
+ return Utils.isEntity(entity) ? expand(entity) : item;
341
+ };
333
342
  const w = where[k];
334
- if (Utils.isEntity(w)) {
335
- where[k] = this.extractJoinColumnValues(w, prop);
343
+ const expanded = expandItem(w);
344
+ if (expanded !== w) {
345
+ where[k] = expanded;
336
346
  }
337
347
  else if (Utils.isPlainObject(w)) {
338
348
  for (const op of Object.keys(w)) {
339
- if (Utils.isOperator(op, false) && Array.isArray(w[op])) {
340
- w[op] = w[op].map((item) => Utils.isEntity(item) ? this.extractJoinColumnValues(item, prop) : item);
349
+ if (!Utils.isOperator(op, false)) {
350
+ continue;
341
351
  }
352
+ w[op] = Array.isArray(w[op]) ? w[op].map(expandItem) : expandItem(w[op]);
342
353
  }
343
354
  }
344
355
  }
@@ -352,6 +363,14 @@ export class QueryHelper {
352
363
  return this.extractColumnValue(entity, prop.targetMeta, refCol);
353
364
  });
354
365
  }
366
+ /**
367
+ * Expands a polymorphic entity reference to `[discriminatorValue, ...joinColumnValues]`,
368
+ * matching the column order of `prop.fieldNames`.
369
+ */
370
+ static extractPolymorphicJoinColumnValues(entity, prop) {
371
+ const discriminator = this.findDiscriminatorValue(prop.discriminatorMap, entity.constructor);
372
+ return [discriminator, ...this.extractJoinColumnValues(entity, prop)];
373
+ }
355
374
  /**
356
375
  * Extracts the value for a specific column from an entity by finding which PK property
357
376
  * owns that column and recursively traversing FK references.
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.12-dev.2';
144
+ static #ORM_VERSION = '7.0.12-dev.4';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */