protected getSort(query: ParsedRequestParams, options: QueryOptions) {
return query.sort && query.sort.length
? this.mapSort(query.sort) // is there really nothing we can get from options.sort in that case?
: options.sort && options.sort.length
? this.mapSort(options.sort)
: {};
}
Thanks for the hard work on this highly useful lib!
I am facing an unexpected result when working with relationship sorting. Default sorting gets overridden as soon as any sorting is specified by the getMany request.
When I specify in MyController that myBaseEntity.myBasesortedRelationship should be sorted by their column order :
I get expected sorted result out of the box (for both getMany and getOne).
However, when getMany is called with any sorting (such as something unrelated to the relationship : sort: [{ field: 'myBaseEntity.date' }]), the linked relationship stop being sorted at all.
For information, there is a related typeorm issue that makes fixing the issue trickier (at least trickier than getSort = mapSort([...query.sort, ...options.sort])): https://github.com/typeorm/typeorm/issues/6294
Hello,
TLDR: When any
sort
is given togetMany
, relationship sorting specified in controller is ignoredLikely culprit:
getSort
in https://github.com/nestjsx/crud/blob/v5.0.1/packages/crud-typeorm/src/typeorm-crud.service.ts#L864-L870Thanks for the hard work on this highly useful lib!
I am facing an unexpected result when working with relationship sorting. Default sorting gets overridden as soon as any sorting is specified by the getMany request.
When I specify in
MyController
thatmyBaseEntity.myBasesortedRelationship
should be sorted by their columnorder
:I get expected sorted result out of the box (for both
getMany
andgetOne
).However, when
getMany
is called with any sorting (such as something unrelated to the relationship :sort: [{ field: 'myBaseEntity.date' }]
), the linked relationship stop being sorted at all.For information, there is a related typeorm issue that makes fixing the issue trickier (at least trickier than
getSort = mapSort([...query.sort, ...options.sort])
): https://github.com/typeorm/typeorm/issues/6294Thanks for the reading