Skip to content

Commit 2ac3bc0

Browse files
committed
fix: filter collections when reassigning results
1 parent 5e17832 commit 2ac3bc0

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.changeset/fluffy-ducks-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"mikro-orm-find-dataloader": minor
3+
---
4+
5+
fix: filter collections when reassigning results

packages/find/src/findDataloader.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ export function getFindBatchLoadFn<Entity extends object>(
488488
for (const [key, value] of Object.entries(filter)) {
489489
const entityValue = entity[key as keyof K];
490490
if (Array.isArray(value)) {
491+
// Our current filter is an array
491492
if (Array.isArray(entityValue)) {
492493
// Collection
493494
if (!value.every((el) => entityValue.includes(el))) {
@@ -500,8 +501,10 @@ export function getFindBatchLoadFn<Entity extends object>(
500501
}
501502
}
502503
} else {
503-
// Object: recursion
504-
if (!filterResult(entityValue as object, value)) {
504+
// Our current filter is an object
505+
if (entityValue instanceof Collection) {
506+
entityValue.find((entity) => filterResult(entity, value));
507+
} else if (!filterResult(entityValue as object, value)) {
505508
return false;
506509
}
507510
}
@@ -522,9 +525,6 @@ export function optsMapToQueries<Entity extends object>(
522525
populate: options.populate === true ? ["*"] : Array.from(options.populate),
523526
}),
524527
} satisfies Pick<FindOptions<any, any>, "populate">;
525-
console.log("entityName", entityName);
526-
console.log("filter", filter);
527-
console.log("findOptions", findOptions);
528528
const entities = await em.find(entityName, filter, findOptions);
529529
return [key, entities];
530530
});

0 commit comments

Comments
 (0)