@mikro-orm/knex 6.4.17-dev.82 → 6.4.17-dev.84
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/AbstractSqlDriver.js +37 -17
- package/package.json +2 -2
package/AbstractSqlDriver.js
CHANGED
|
@@ -866,31 +866,26 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
866
866
|
* @internal
|
|
867
867
|
*/
|
|
868
868
|
mergeJoinedResult(rawResults, meta, joinedProps) {
|
|
869
|
+
if (rawResults.length <= 1) {
|
|
870
|
+
return rawResults;
|
|
871
|
+
}
|
|
869
872
|
const res = [];
|
|
870
873
|
const map = {};
|
|
874
|
+
const collectionsToMerge = {};
|
|
875
|
+
const hints = joinedProps.map(hint => {
|
|
876
|
+
const [propName, ref] = hint.field.split(':', 2);
|
|
877
|
+
return { propName, ref, children: hint.children };
|
|
878
|
+
});
|
|
871
879
|
for (const item of rawResults) {
|
|
872
880
|
const pk = core_1.Utils.getCompositeKeyHash(item, meta);
|
|
873
881
|
if (map[pk]) {
|
|
874
|
-
for (const
|
|
875
|
-
const [propName, ref] = hint.field.split(':', 2);
|
|
876
|
-
const prop = meta.properties[propName];
|
|
882
|
+
for (const { propName } of hints) {
|
|
877
883
|
if (!item[propName]) {
|
|
878
884
|
continue;
|
|
879
885
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
}
|
|
884
|
-
switch (prop.kind) {
|
|
885
|
-
case core_1.ReferenceKind.ONE_TO_MANY:
|
|
886
|
-
case core_1.ReferenceKind.MANY_TO_MANY:
|
|
887
|
-
map[pk][propName] = this.mergeJoinedResult([...map[pk][propName], ...item[propName]], prop.targetMeta, hint.children ?? []);
|
|
888
|
-
break;
|
|
889
|
-
case core_1.ReferenceKind.MANY_TO_ONE:
|
|
890
|
-
case core_1.ReferenceKind.ONE_TO_ONE:
|
|
891
|
-
map[pk][propName] = this.mergeJoinedResult([map[pk][propName], item[propName]], prop.targetMeta, hint.children ?? [])[0];
|
|
892
|
-
break;
|
|
893
|
-
}
|
|
886
|
+
collectionsToMerge[pk] ??= {};
|
|
887
|
+
collectionsToMerge[pk][propName] ??= [map[pk][propName]];
|
|
888
|
+
collectionsToMerge[pk][propName].push(item[propName]);
|
|
894
889
|
}
|
|
895
890
|
}
|
|
896
891
|
else {
|
|
@@ -898,6 +893,31 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
898
893
|
res.push(item);
|
|
899
894
|
}
|
|
900
895
|
}
|
|
896
|
+
for (const pk in collectionsToMerge) {
|
|
897
|
+
const entity = map[pk];
|
|
898
|
+
const collections = collectionsToMerge[pk];
|
|
899
|
+
for (const { propName, ref, children } of hints) {
|
|
900
|
+
if (!collections[propName]) {
|
|
901
|
+
continue;
|
|
902
|
+
}
|
|
903
|
+
const prop = meta.properties[propName];
|
|
904
|
+
const items = collections[propName].flat();
|
|
905
|
+
if ([core_1.ReferenceKind.ONE_TO_MANY, core_1.ReferenceKind.MANY_TO_MANY].includes(prop.kind) && ref) {
|
|
906
|
+
entity[propName] = items;
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
switch (prop.kind) {
|
|
910
|
+
case core_1.ReferenceKind.ONE_TO_MANY:
|
|
911
|
+
case core_1.ReferenceKind.MANY_TO_MANY:
|
|
912
|
+
entity[propName] = this.mergeJoinedResult(items, prop.targetMeta, children ?? []);
|
|
913
|
+
break;
|
|
914
|
+
case core_1.ReferenceKind.MANY_TO_ONE:
|
|
915
|
+
case core_1.ReferenceKind.ONE_TO_ONE:
|
|
916
|
+
entity[propName] = this.mergeJoinedResult(items, prop.targetMeta, children ?? [])[0];
|
|
917
|
+
break;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
901
921
|
return res;
|
|
902
922
|
}
|
|
903
923
|
getFieldsForJoinedLoad(qb, meta, explicitFields, exclude, populate = [], options, parentTableAlias, parentJoinPath, count) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.4.17-dev.
|
|
3
|
+
"version": "6.4.17-dev.84",
|
|
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.16"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.4.17-dev.
|
|
69
|
+
"@mikro-orm/core": "6.4.17-dev.84",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|