@mikro-orm/knex 6.6.5-dev.4 → 6.6.5-dev.5

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.
@@ -250,7 +250,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
250
250
  relationPojo[prop.name] = root[alias];
251
251
  }
252
252
  });
253
- const mapToPk = !!(ref || prop.mapToPk);
253
+ const mapToPk = !hint.dataOnly && !!(ref || prop.mapToPk);
254
254
  const targetProps = mapToPk
255
255
  ? meta2.getPrimaryProps()
256
256
  : meta2.props.filter(prop => this.platform.shouldHaveColumn(prop, hint.children || []));
@@ -437,19 +437,21 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
437
437
  }
438
438
  if (prop.fieldNames.length > 1) {
439
439
  const newFields = [];
440
- const allParam = [...core_1.Utils.asArray(row[prop.name]) ?? prop.fieldNames.map(() => null)];
440
+ const rawParam = core_1.Utils.asArray(row[prop.name]) ?? prop.fieldNames.map(() => null);
441
+ // Deep flatten nested arrays when needed (for deeply nested composite keys like Tag -> Comment -> Post -> User)
442
+ const needsFlatten = rawParam.length !== prop.fieldNames.length && rawParam.some(v => Array.isArray(v));
443
+ const allParam = needsFlatten ? core_1.Utils.flatten(rawParam, true) : rawParam;
441
444
  // TODO(v7): instead of making this conditional here, the entity snapshot should respect `ownColumns`,
442
445
  // but that means changing the compiled PK getters, which might be seen as breaking
443
446
  const columns = allParam.length > 1 ? prop.fieldNames : prop.ownColumns;
444
- const newParam = [];
447
+ const param = [];
445
448
  columns.forEach((field, idx) => {
446
449
  if (usedDups.includes(field)) {
447
450
  return;
448
451
  }
449
452
  newFields.push(field);
450
- newParam.push(allParam[idx]);
453
+ param.push(allParam[idx]);
451
454
  });
452
- const param = core_1.Utils.flatten(newParam);
453
455
  newFields.forEach((field, idx) => {
454
456
  if (!duplicates.includes(field) || !usedDups.includes(field)) {
455
457
  params.push(param[idx]);
@@ -801,7 +803,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
801
803
  fields,
802
804
  exclude: childExclude,
803
805
  orderBy: this.getPivotOrderBy(prop, pivotProp1, orderBy, options?.orderBy),
804
- populate: [{ field: populateField, strategy: core_1.LoadStrategy.JOINED, joinType: query_1.JoinType.innerJoin, children: populate }],
806
+ populate: [{ field: populateField, strategy: core_1.LoadStrategy.JOINED, joinType: query_1.JoinType.innerJoin, children: populate, dataOnly: pivotProp1.mapToPk && !pivotJoin }],
805
807
  populateWhere: undefined,
806
808
  // @ts-ignore
807
809
  _populateWhere: 'infer',
@@ -989,10 +991,10 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
989
991
  }
990
992
  });
991
993
  const childExclude = exclude ? core_1.Utils.extractChildElements(exclude, prop.name) : exclude;
992
- if (!ref && !prop.mapToPk) {
994
+ if (!ref && (!prop.mapToPk || hint.dataOnly)) {
993
995
  fields.push(...this.getFieldsForJoinedLoad(qb, meta2, childExplicitFields.length === 0 ? undefined : childExplicitFields, childExclude, hint.children, options, tableAlias, path));
994
996
  }
995
- else if (hint.filter || prop.mapToPk || (ref && [core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind))) {
997
+ else if (hint.filter || (prop.mapToPk && !hint.dataOnly) || (ref && [core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind))) {
996
998
  fields.push(...prop.referencedColumnNames.map(col => qb.helper.mapper(`${tableAlias}.${col}`, qb.type, undefined, `${tableAlias}__${col}`)));
997
999
  }
998
1000
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.6.5-dev.4",
3
+ "version": "6.6.5-dev.5",
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",
@@ -66,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.6.4"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.6.5-dev.4",
69
+ "@mikro-orm/core": "6.6.5-dev.5",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"