nestjs-paginate
nestjs-paginate copied to clipboard
Filter does not work with QueryBuilder
If I use a querybuilder, the filters doesnt work. Is this not supported by default?
The problem here is that the filter is attached to the where clause at the end. Using an orWhere can lead to problems. As a workaround, I only used a where clause and separated it from the added filter with addittional brackets.
hi there, filter using query builder isn't currently covered by any test - but it might work. could you elaborate in more detail the issue? (code lines + generated SQL)
// does not work
const query = this.getBasicDocumentQuery();
query
.where('document.id IN (' + this.someRandomCheck()+ ')', {
id,
})
.orWhere(
'document.id IN (' +
this.someOtherRandomCheck() +
')',
{ id },
);
// is working
const query = this.getBasicDocumentQuery();
query.where(
'(document.id IN (' +
this.someRandomCheck() +
') OR document.id IN (' +
this.someOtherRandomCheck() +
'))',
{
id,
},
);
This happened because the filter just add a "AND filterField = filter" at the end of the query. Just add the extra brackets and it will work. For me this workaround is fine for now. Not sure if I find the time for a pull request
works. see https://github.com/ppetzold/nestjs-paginate/commit/ab24b887025313a4e5d12ac532ab0bad1e13c7d9