@mikro-orm/sql 7.0.15-dev.8 → 7.0.15-dev.9

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/sql",
3
- "version": "7.0.15-dev.8",
3
+ "version": "7.0.15-dev.9",
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",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.0.14"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.0.15-dev.8"
56
+ "@mikro-orm/core": "7.0.15-dev.9"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -1347,6 +1347,7 @@ export class QueryBuilder {
1347
1347
  aliased: [QueryType.SELECT, QueryType.COUNT].includes(this.type),
1348
1348
  });
1349
1349
  const criteriaNode = CriteriaNodeFactory.createNode(this.metadata, prop.targetMeta.class, cond);
1350
+ const joinCountBefore = Object.keys(this.#state.joins).length;
1350
1351
  cond = criteriaNode.process(this, { ignoreBranching: true, alias });
1351
1352
  let aliasedName = `${fromAlias}.${prop.name}#${alias}`;
1352
1353
  path ??= `${Object.values(this.#state.joins).find(j => j.alias === fromAlias)?.path ?? Utils.className(entityName)}.${prop.name}`;
@@ -1376,6 +1377,20 @@ export class QueryBuilder {
1376
1377
  this.#state.joins[aliasedName] = this.helper.joinManyToOneReference(prop, ownerAlias, alias, type, cond, schema);
1377
1378
  this.#state.joins[aliasedName].path ??= path;
1378
1379
  }
1380
+ // auto-joins added by cond processing that depend on the new alias would otherwise produce a
1381
+ // forward reference (the auto-join's ON refers to alias, while alias's ON refers back to it);
1382
+ // fold them into the new join so both aliases share scope in the outer ON clause (issue #7681)
1383
+ const condJoin = this.#state.joins[aliasedName];
1384
+ const joinKeys = Object.keys(this.#state.joins);
1385
+ for (let i = joinCountBefore; i < joinKeys.length; i++) {
1386
+ const j = this.#state.joins[joinKeys[i]];
1387
+ if (j === condJoin || j.ownerAlias !== alias) {
1388
+ continue;
1389
+ }
1390
+ const nested = (condJoin.nested ??= new Set());
1391
+ j.type = j.type === JoinType.innerJoin ? JoinType.nestedInnerJoin : JoinType.nestedLeftJoin;
1392
+ nested.add(j);
1393
+ }
1379
1394
  return { prop, key: aliasedName };
1380
1395
  }
1381
1396
  prepareFields(fields, type = 'where', schema) {