nestjs-paginate
nestjs-paginate copied to clipboard
Is there a way to include null values when filtering on relations ?
At the moment, since filtering on relations act as a simplified left join, if the requested relation is null, the results are not included. I think it's not the right behaviour, since for example if I ask for cats filtering by toys.color=$not:$eq:red, I expect cats that do not have any toys to show up as well (but that's debatable ofc)
Left joins should include null values 🤔 Inner joins don't. Can you see if adding a 2nd filter with toys.color=$or:$null gets you the correct results?
@jlefebvre1997 have you had a chance to look into the added null filter? If you have the time, could you open a PR where you add a failing test case to demonstrate the problem? Then I can look into a fix :)
Hey @Helveg,
I think I have a similar problem or the same. I'm having a OneToOne relationship between the entities, so the field can be null, or contain the joined entity.
When filtering with no filter: Result: 21 total items (All in my DB)
When filtering with:
"filter": {
"occurrence.status.label": "$not:$eq:fixed"
}
Result: 1 total item So only Occurrence Entities are include which have status not null and not fixed
When filtering with following filter as suggested in the comments earlier:
"filter": {
"occurrence.status.label": [
"$not:$eq:fixed",
"$or:$null"
]
}
Result: 1 total item So the entities with status = null are still not included
Any idea why this is not correct or did I use the filter wrong?
had to set the joinMethods to left join. Now it works for me