@mikro-orm/core 6.6.9-dev.2 → 6.6.9-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": "6.6.9-dev.2",
3
+ "version": "6.6.9-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
  "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.9-dev.2",
67
+ "mikro-orm": "6.6.9-dev.4",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -22,6 +22,22 @@ export declare class QueryHelper {
22
22
  private static processJsonCondition;
23
23
  private static getValueType;
24
24
  static findProperty<T>(fieldName: string, options: ProcessWhereOptions<T>): EntityProperty<T> | undefined;
25
+ /**
26
+ * Converts entity references for composite FK properties into flat arrays
27
+ * of correctly-ordered join column values, before processParams flattens them
28
+ * incorrectly due to shared FK columns.
29
+ */
30
+ private static convertCompositeEntityRefs;
31
+ /**
32
+ * Extracts values for a FK's join columns from an entity by traversing the FK chain.
33
+ * Handles shared FK columns (e.g., tenant_id referenced by multiple FKs) correctly.
34
+ */
35
+ private static extractJoinColumnValues;
36
+ /**
37
+ * Extracts the value for a specific column from an entity by finding which PK property
38
+ * owns that column and recursively traversing FK references.
39
+ */
40
+ private static extractColumnValue;
25
41
  }
26
42
  interface ProcessWhereOptions<T> {
27
43
  where: FilterQuery<T>;
@@ -117,6 +117,9 @@ class QueryHelper {
117
117
  QueryHelper.liftGroupOperators(where, meta, metadata);
118
118
  QueryHelper.inlinePrimaryKeyObjects(where, meta, metadata);
119
119
  }
120
+ if (meta) {
121
+ QueryHelper.convertCompositeEntityRefs(where, meta);
122
+ }
120
123
  if (options.platform.getConfig().get('ignoreUndefinedInQuery') && where && typeof where === 'object') {
121
124
  Utils_1.Utils.dropUndefinedProperties(where);
122
125
  }
@@ -293,5 +296,70 @@ class QueryHelper {
293
296
  const meta = entityName ? options.metadata.find(entityName) : undefined;
294
297
  return meta?.properties[propName];
295
298
  }
299
+ /**
300
+ * Converts entity references for composite FK properties into flat arrays
301
+ * of correctly-ordered join column values, before processParams flattens them
302
+ * incorrectly due to shared FK columns.
303
+ */
304
+ static convertCompositeEntityRefs(where, meta) {
305
+ if (!Utils_1.Utils.isPlainObject(where)) {
306
+ return;
307
+ }
308
+ for (const k of Object.keys(where)) {
309
+ if (k in enums_1.GroupOperator) {
310
+ if (Array.isArray(where[k])) {
311
+ where[k].forEach((sub) => this.convertCompositeEntityRefs(sub, meta));
312
+ }
313
+ continue;
314
+ }
315
+ if (k === '$not') {
316
+ this.convertCompositeEntityRefs(where[k], meta);
317
+ continue;
318
+ }
319
+ const prop = meta.properties[k];
320
+ if (!prop?.joinColumns || prop.joinColumns.length <= 1) {
321
+ continue;
322
+ }
323
+ const w = where[k];
324
+ if (Utils_1.Utils.isEntity(w)) {
325
+ where[k] = this.extractJoinColumnValues(w, prop);
326
+ }
327
+ else if (Utils_1.Utils.isPlainObject(w)) {
328
+ for (const op of Object.keys(w)) {
329
+ if (Utils_1.Utils.isOperator(op, false) && Array.isArray(w[op])) {
330
+ w[op] = w[op].map((item) => Utils_1.Utils.isEntity(item) ? this.extractJoinColumnValues(item, prop) : item);
331
+ }
332
+ }
333
+ }
334
+ }
335
+ }
336
+ /**
337
+ * Extracts values for a FK's join columns from an entity by traversing the FK chain.
338
+ * Handles shared FK columns (e.g., tenant_id referenced by multiple FKs) correctly.
339
+ */
340
+ static extractJoinColumnValues(entity, prop) {
341
+ return prop.referencedColumnNames.map(refCol => {
342
+ return this.extractColumnValue(entity, prop.targetMeta, refCol);
343
+ });
344
+ }
345
+ /**
346
+ * Extracts the value for a specific column from an entity by finding which PK property
347
+ * owns that column and recursively traversing FK references.
348
+ */
349
+ static extractColumnValue(entity, meta, columnName) {
350
+ for (const pk of meta.primaryKeys) {
351
+ const pkProp = meta.properties[pk];
352
+ const colIdx = pkProp.fieldNames.indexOf(columnName);
353
+ if (colIdx !== -1) {
354
+ const value = entity[pk];
355
+ if (pkProp.targetMeta && Utils_1.Utils.isEntity(value, true)) {
356
+ const refCol = pkProp.referencedColumnNames[colIdx];
357
+ return this.extractColumnValue(value, pkProp.targetMeta, refCol);
358
+ }
359
+ return value;
360
+ }
361
+ }
362
+ return null;
363
+ }
296
364
  }
297
365
  exports.QueryHelper = QueryHelper;