nestjs-paginate
nestjs-paginate copied to clipboard
Using `$null` on non-terminal relationship returns empty results
Since https://github.com/ppetzold/nestjs-paginate/pull/539 was merged, using filter.rel_A=$null while also specifying relations: ['rel_A.rel_B'] in the config results in an unexpected INNER JOIN on rel_A. This causes records where rel_A is NULL to be filtered out, leading to empty results.
Steps to Reproduce
- Configure pagination with:
{ relations: ['rel_A.rel_B'] } - Apply the filter:
filter.rel_A.id=$null - The generated query INNER JOINs
rel_A, excluding records whererel_A IS NULL.
Expected Behavior
rel_Ashould be LEFT JOINED to preserve NULL values when filtering for primary keys ofrel_A.id=$null.
Workaround
- Adding
joinMethods: { rel_A: 'leftJoinAndSelect' }to the config prevents this issue.{ relations: ['rel_A.rel_B'], joinMethods: { rel_A: 'leftJoinAndSelect' } } - However, this behavior is unintended.
Suggested fix
Adding filters creates a map of columns to be left/inner joined here:
https://github.com/ppetzold/nestjs-paginate/blob/2b717aa85be7844980d526df908761cf189655e4/src/filter.ts#L394-L406
When a $null filter is added, then that column's value in the map should be set to leftJoinAndSelect, unless the user's configuration changes it.