@mikro-orm/sql 7.2.10-dev.3 → 7.2.10-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/sql",
|
|
3
|
-
"version": "7.2.10-dev.
|
|
3
|
+
"version": "7.2.10-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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.2.9"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.10-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.10-dev.4"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -1031,6 +1031,11 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
1031
1031
|
*/
|
|
1032
1032
|
private processNestedJoins;
|
|
1033
1033
|
private hasToManyJoins;
|
|
1034
|
+
/**
|
|
1035
|
+
* Whether a join can match more than one row per root row. Only owning to-one joins target a unique key; inverse 1:1
|
|
1036
|
+
* relies on an unenforced unique FK, and sub-query or table reference joins match arbitrary rows.
|
|
1037
|
+
*/
|
|
1038
|
+
private canRepeatRootRows;
|
|
1034
1039
|
/**
|
|
1035
1040
|
* Resolves a `persist: false` virtual field referenced in `orderBy` (e.g. `qb.as('reviewCount')` or a
|
|
1036
1041
|
* `raw()` fragment aliased in the select) to the alias and SQL expression it was selected under. The
|
package/query/QueryBuilder.js
CHANGED
|
@@ -1117,7 +1117,7 @@ export class QueryBuilder {
|
|
|
1117
1117
|
if (Array.isArray(res)) {
|
|
1118
1118
|
const map = {};
|
|
1119
1119
|
mapped = res.map(r => this.driver.mapResult(r, meta, this.#state.populate, this, map));
|
|
1120
|
-
if (options.mergeResults && joinedProps.length > 0) {
|
|
1120
|
+
if (options.mergeResults && joinedProps.length > 0 && this.canRepeatRootRows()) {
|
|
1121
1121
|
mapped = this.driver.mergeJoinedResult(mapped, this.mainAlias.meta, joinedProps);
|
|
1122
1122
|
}
|
|
1123
1123
|
}
|
|
@@ -2274,6 +2274,17 @@ export class QueryBuilder {
|
|
|
2274
2274
|
return [ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(join.prop.kind);
|
|
2275
2275
|
});
|
|
2276
2276
|
}
|
|
2277
|
+
/**
|
|
2278
|
+
* Whether a join can match more than one row per root row. Only owning to-one joins target a unique key; inverse 1:1
|
|
2279
|
+
* relies on an unenforced unique FK, and sub-query or table reference joins match arbitrary rows.
|
|
2280
|
+
*/
|
|
2281
|
+
canRepeatRootRows() {
|
|
2282
|
+
return Object.values(this.#state.joins).some(join => {
|
|
2283
|
+
const { kind, owner, name } = join.prop;
|
|
2284
|
+
const uniqueTarget = kind === ReferenceKind.MANY_TO_ONE || (kind === ReferenceKind.ONE_TO_ONE && owner);
|
|
2285
|
+
return !uniqueTarget || join.subquery != null || name === '__subquery__';
|
|
2286
|
+
});
|
|
2287
|
+
}
|
|
2277
2288
|
/**
|
|
2278
2289
|
* Resolves a `persist: false` virtual field referenced in `orderBy` (e.g. `qb.as('reviewCount')` or a
|
|
2279
2290
|
* `raw()` fragment aliased in the select) to the alias and SQL expression it was selected under. The
|
|
@@ -9,7 +9,10 @@ export class ScalarCriteriaNode extends CriteriaNode {
|
|
|
9
9
|
process(qb, options) {
|
|
10
10
|
const matchPopulateJoins = options?.matchPopulateJoins ||
|
|
11
11
|
(this.prop && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(this.prop.kind));
|
|
12
|
-
|
|
12
|
+
// nodes without a property (e.g. `$in` items) never join, so the alias lookup is not needed
|
|
13
|
+
const nestedAlias = this.prop
|
|
14
|
+
? qb.getAliasForJoinPath(this.getPath(options), { ...options, matchPopulateJoins })
|
|
15
|
+
: undefined;
|
|
13
16
|
if (this.shouldJoin(qb, nestedAlias)) {
|
|
14
17
|
const path = this.getPath();
|
|
15
18
|
const parentPath = this.parent.getPath(); // the parent is always there, otherwise `shouldJoin` would return `false`
|