@mikro-orm/sql 7.1.10-dev.3 → 7.1.10-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.
- package/package.json +2 -2
- package/query/QueryBuilder.d.ts +6 -0
- package/query/QueryBuilder.js +24 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.10-dev.
|
|
3
|
+
"version": "7.1.10-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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.1.9"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.10-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.10-dev.5"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -506,6 +506,12 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
506
506
|
* @internal
|
|
507
507
|
*/
|
|
508
508
|
applyJoinedFilters(em: EntityManager, filterOptions: FilterOptions | undefined): Promise<void>;
|
|
509
|
+
/**
|
|
510
|
+
* Auto-joins added while processing a condition of `condJoin` would render after it and produce a
|
|
511
|
+
* forward alias reference in its `on` clause. Fold them into `condJoin`, so they render as a single
|
|
512
|
+
* parenthesized join group and share the scope of the outer `on` clause (issue #7681).
|
|
513
|
+
*/
|
|
514
|
+
private nestNewJoins;
|
|
509
515
|
withSubQuery(subQuery: RawQueryFragment | NativeQueryBuilder, alias: string): this;
|
|
510
516
|
/**
|
|
511
517
|
* Adds a WHERE clause to the query using an object condition.
|
package/query/QueryBuilder.js
CHANGED
|
@@ -411,6 +411,7 @@ export class QueryBuilder {
|
|
|
411
411
|
filterOptions = QueryHelper.mergePropertyFilters(join.prop.filters, filterOptions);
|
|
412
412
|
let cond = await em.applyFilters(join.prop.targetMeta.class, join.cond, filterOptions, 'read');
|
|
413
413
|
const criteriaNode = CriteriaNodeFactory.createNode(this.metadata, join.prop.targetMeta.class, cond);
|
|
414
|
+
const joinCountBefore = Object.keys(this.#state.joins).length;
|
|
414
415
|
cond = criteriaNode.process(this, {
|
|
415
416
|
matchPopulateJoins: true,
|
|
416
417
|
filter: true,
|
|
@@ -418,6 +419,7 @@ export class QueryBuilder {
|
|
|
418
419
|
ignoreBranching: true,
|
|
419
420
|
parentPath: join.path,
|
|
420
421
|
});
|
|
422
|
+
this.nestNewJoins(join, joinCountBefore);
|
|
421
423
|
if (Utils.hasObjectKeys(cond) || RawQueryFragment.hasObjectFragments(cond)) {
|
|
422
424
|
// remove nested filters, we only care about scalars here, nesting would require another join branch
|
|
423
425
|
for (const key of Object.keys(cond)) {
|
|
@@ -456,6 +458,27 @@ export class QueryBuilder {
|
|
|
456
458
|
}
|
|
457
459
|
}
|
|
458
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* Auto-joins added while processing a condition of `condJoin` would render after it and produce a
|
|
463
|
+
* forward alias reference in its `on` clause. Fold them into `condJoin`, so they render as a single
|
|
464
|
+
* parenthesized join group and share the scope of the outer `on` clause (issue #7681).
|
|
465
|
+
*/
|
|
466
|
+
nestNewJoins(condJoin, joinCountBefore) {
|
|
467
|
+
// m:n pivot joins might not have the target join entry created
|
|
468
|
+
if (!condJoin) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
const joinKeys = Object.keys(this.#state.joins);
|
|
472
|
+
for (let i = joinCountBefore; i < joinKeys.length; i++) {
|
|
473
|
+
const j = this.#state.joins[joinKeys[i]];
|
|
474
|
+
if (j === condJoin || j.ownerAlias !== condJoin.alias) {
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
const nested = (condJoin.nested ??= new Set());
|
|
478
|
+
j.type = j.type === JoinType.innerJoin ? JoinType.nestedInnerJoin : JoinType.nestedLeftJoin;
|
|
479
|
+
nested.add(j);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
459
482
|
withSubQuery(subQuery, alias) {
|
|
460
483
|
this.ensureNotFinalized();
|
|
461
484
|
if (isRaw(subQuery)) {
|
|
@@ -1444,20 +1467,7 @@ export class QueryBuilder {
|
|
|
1444
1467
|
this.#state.joins[aliasedName] = this.helper.joinManyToOneReference(prop, ownerAlias, alias, type, cond, schema);
|
|
1445
1468
|
this.#state.joins[aliasedName].path ??= path;
|
|
1446
1469
|
}
|
|
1447
|
-
|
|
1448
|
-
// forward reference (the auto-join's ON refers to alias, while alias's ON refers back to it);
|
|
1449
|
-
// fold them into the new join so both aliases share scope in the outer ON clause (issue #7681)
|
|
1450
|
-
const condJoin = this.#state.joins[aliasedName];
|
|
1451
|
-
const joinKeys = Object.keys(this.#state.joins);
|
|
1452
|
-
for (let i = joinCountBefore; i < joinKeys.length; i++) {
|
|
1453
|
-
const j = this.#state.joins[joinKeys[i]];
|
|
1454
|
-
if (j === condJoin || j.ownerAlias !== alias) {
|
|
1455
|
-
continue;
|
|
1456
|
-
}
|
|
1457
|
-
const nested = (condJoin.nested ??= new Set());
|
|
1458
|
-
j.type = j.type === JoinType.innerJoin ? JoinType.nestedInnerJoin : JoinType.nestedLeftJoin;
|
|
1459
|
-
nested.add(j);
|
|
1460
|
-
}
|
|
1470
|
+
this.nestNewJoins(this.#state.joins[aliasedName], joinCountBefore);
|
|
1461
1471
|
return { prop, key: aliasedName };
|
|
1462
1472
|
}
|
|
1463
1473
|
prepareFields(fields, type = 'where', schema) {
|