@guren/orm 1.0.0-rc.23 → 1.0.0-rc.25
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/dist/index.d.ts +3 -1
- package/dist/index.js +4 -54
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -242,7 +242,9 @@ declare class QueryBuilder<TRecord extends PlainObject = PlainObject, TResult ex
|
|
|
242
242
|
private toSimpleWhereClause;
|
|
243
243
|
/**
|
|
244
244
|
* Load eager relations onto fetched results.
|
|
245
|
-
* Supports dot notation for nested relations
|
|
245
|
+
* Supports dot notation for nested relations at any depth
|
|
246
|
+
* (e.g., 'posts.comments.author') — the full path is delegated to
|
|
247
|
+
* Model.loadRelationInto, which recurses through the relation chain.
|
|
246
248
|
*/
|
|
247
249
|
private readonly loadEagerRelations;
|
|
248
250
|
}
|
package/dist/index.js
CHANGED
|
@@ -879,70 +879,20 @@ var QueryBuilder = class {
|
|
|
879
879
|
}
|
|
880
880
|
/**
|
|
881
881
|
* Load eager relations onto fetched results.
|
|
882
|
-
* Supports dot notation for nested relations
|
|
882
|
+
* Supports dot notation for nested relations at any depth
|
|
883
|
+
* (e.g., 'posts.comments.author') — the full path is delegated to
|
|
884
|
+
* Model.loadRelationInto, which recurses through the relation chain.
|
|
883
885
|
*/
|
|
884
886
|
loadEagerRelations = async (results) => {
|
|
885
887
|
if (this.eagerLoad.length === 0 || results.length === 0) return results;
|
|
886
888
|
const copies = results.map((r) => ({ ...r }));
|
|
887
889
|
const model = this.modelClass;
|
|
888
890
|
for (const relation of this.eagerLoad) {
|
|
889
|
-
|
|
890
|
-
const topLevel = parts[0];
|
|
891
|
-
await model.loadRelationInto(copies, topLevel);
|
|
892
|
-
if (parts.length > 1) {
|
|
893
|
-
const nestedName = parts.slice(1).join(".");
|
|
894
|
-
const nestedRecords = [];
|
|
895
|
-
for (const record of copies) {
|
|
896
|
-
const related = record[topLevel];
|
|
897
|
-
if (Array.isArray(related)) {
|
|
898
|
-
nestedRecords.push(...related);
|
|
899
|
-
} else if (related && typeof related === "object") {
|
|
900
|
-
nestedRecords.push(related);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
if (nestedRecords.length > 0) {
|
|
904
|
-
const topDef = model.getRelationDefinition(topLevel);
|
|
905
|
-
if (topDef) {
|
|
906
|
-
const relatedModel = await resolveRelatedModel(topDef.related);
|
|
907
|
-
if (relatedModel) {
|
|
908
|
-
const nestedModel = relatedModel;
|
|
909
|
-
const nestedParts = parts.slice(1);
|
|
910
|
-
await nestedModel.loadRelationInto(nestedRecords, nestedParts[0]);
|
|
911
|
-
if (nestedParts.length > 1) {
|
|
912
|
-
for (let i = 1; i < nestedParts.length; i++) {
|
|
913
|
-
const subRecords = [];
|
|
914
|
-
for (const nr of nestedRecords) {
|
|
915
|
-
const sub = nr[nestedParts[i - 1]];
|
|
916
|
-
if (Array.isArray(sub)) subRecords.push(...sub);
|
|
917
|
-
else if (sub && typeof sub === "object") subRecords.push(sub);
|
|
918
|
-
}
|
|
919
|
-
if (subRecords.length === 0) break;
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
891
|
+
await model.loadRelationInto(copies, relation);
|
|
926
892
|
}
|
|
927
893
|
return copies;
|
|
928
894
|
};
|
|
929
895
|
};
|
|
930
|
-
async function resolveRelatedModel(reference) {
|
|
931
|
-
if (typeof reference === "function" && "prototype" in reference) {
|
|
932
|
-
try {
|
|
933
|
-
if (reference.resolveTable) return reference;
|
|
934
|
-
} catch {
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
if (typeof reference === "function") {
|
|
938
|
-
try {
|
|
939
|
-
return await reference();
|
|
940
|
-
} catch {
|
|
941
|
-
return null;
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
return null;
|
|
945
|
-
}
|
|
946
896
|
|
|
947
897
|
// src/serialization.ts
|
|
948
898
|
function serializeRecord(record, options) {
|