Skip to content

Commit

Permalink
fix(query-mongoose): ReferenceQueryService only accepted Relations wi…
Browse files Browse the repository at this point in the history
…th 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.
  • Loading branch information
TriPSs authored Jan 13, 2025
2 parents 09e9eea + 58e3e1f commit 14175fb
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ export abstract class ReferenceQueryService<Entity extends Document> {
const refs = entityRelations.filter((er) => {
return referenceIds.some((rid) => {
const oneOrManyIds = er[refFieldMap.foreignField as keyof Relation]
const ids = (Array.isArray(oneOrManyIds) ? oneOrManyIds : [oneOrManyIds]) as Types.ObjectId[]
return ids.some((id) => id.equals(rid as Types.ObjectId))
const ids = Array.isArray(oneOrManyIds) ? oneOrManyIds : [oneOrManyIds]
return ids.some((id) => String(id) === String(rid))
})
})
results.set(dto, await assembler.convertToDTOs(refs))
Expand Down

0 comments on commit 14175fb

Please sign in to comment.