@mikro-orm/knex 6.4.2-dev.2 → 6.4.2-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.
@@ -248,7 +248,8 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
248
248
  relationPojo[prop.name] = root[alias];
249
249
  }
250
250
  });
251
- const targetProps = ref
251
+ const mapToPk = !!(ref || prop.mapToPk);
252
+ const targetProps = mapToPk
252
253
  ? meta2.getPrimaryProps()
253
254
  : meta2.props.filter(prop => this.platform.shouldHaveColumn(prop, hint.children || []));
254
255
  const tz = this.platform.getTimezone();
@@ -290,7 +291,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
290
291
  for (const prop of targetProps) {
291
292
  prop.fieldNames.map(name => delete root[`${relationAlias}__${name}`]);
292
293
  }
293
- if (ref) {
294
+ if (mapToPk) {
294
295
  const tmp = Object.values(relationPojo);
295
296
  /* istanbul ignore next */
296
297
  relationPojo = (meta2.compositePK ? tmp : tmp[0]);
@@ -870,6 +871,10 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
870
871
  if (hint.filter && hint.strategy === core_1.LoadStrategy.JOINED) {
871
872
  return true;
872
873
  }
874
+ // skip redundant joins for 1:1 owner population hints when using `mapToPk`
875
+ if (prop.kind === core_1.ReferenceKind.ONE_TO_ONE && prop.mapToPk && prop.owner) {
876
+ return false;
877
+ }
873
878
  if ((options?.strategy || hint.strategy || prop.strategy || this.config.get('loadStrategy')) !== core_1.LoadStrategy.JOINED) {
874
879
  // force joined strategy for explicit 1:1 owner populate hint as it would require a join anyway
875
880
  return prop.kind === core_1.ReferenceKind.ONE_TO_ONE && !prop.owner;
@@ -972,10 +977,10 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
972
977
  }
973
978
  });
974
979
  const childExclude = exclude ? core_1.Utils.extractChildElements(exclude, prop.name) : exclude;
975
- if (!ref) {
980
+ if (!ref && !prop.mapToPk) {
976
981
  fields.push(...this.getFieldsForJoinedLoad(qb, meta2, childExplicitFields.length === 0 ? undefined : childExplicitFields, childExclude, hint.children, options, tableAlias, path, count));
977
982
  }
978
- else if (hint.filter) {
983
+ else if (hint.filter || prop.mapToPk) {
979
984
  fields.push(...prop.referencedColumnNames.map(col => qb.helper.mapper(`${tableAlias}.${col}`, qb.type, undefined, `${tableAlias}__${col}`)));
980
985
  }
981
986
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.4.2-dev.2",
3
+ "version": "6.4.2-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",
@@ -66,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.4.1"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.4.2-dev.2",
69
+ "@mikro-orm/core": "6.4.2-dev.4",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"