Skip to content

Commit 14175fb

Browse files
authored
fix(query-mongoose): ReferenceQueryService only accepted Relations with ObjectIds (#340)
There is a hard limitation in `ReferenceQueryService` that can only handle Relations/UnpagedRelations when the id fields are of type `ObjectId`. Since you can make relations with all kinds of field types in mongoose, nestjs-query should also support it.
2 parents 09e9eea + 58e3e1f commit 14175fb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

packages/query-mongoose/src/services/reference-query.service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ export abstract class ReferenceQueryService<Entity extends Document> {
195195
const refs = entityRelations.filter((er) => {
196196
return referenceIds.some((rid) => {
197197
const oneOrManyIds = er[refFieldMap.foreignField as keyof Relation]
198-
const ids = (Array.isArray(oneOrManyIds) ? oneOrManyIds : [oneOrManyIds]) as Types.ObjectId[]
199-
return ids.some((id) => id.equals(rid as Types.ObjectId))
198+
const ids = Array.isArray(oneOrManyIds) ? oneOrManyIds : [oneOrManyIds]
199+
return ids.some((id) => String(id) === String(rid))
200200
})
201201
})
202202
results.set(dto, await assembler.convertToDTOs(refs))

0 commit comments

Comments
 (0)