Skip to content

Commit 92d26ba

Browse files
authored
fix: move the queryBuilder to enable withDeleted #973 (#974)
1 parent 606bc25 commit 92d26ba

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/paginate.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,21 @@ describe('paginate', () => {
23822382
await catRepo.restore({ id: cats[0].id })
23832383
})
23842384

2385+
it('should return all relation items even if deleted', async () => {
2386+
const config: PaginateConfig<CatHomeEntity> = {
2387+
sortableColumns: ['id'],
2388+
withDeleted: true,
2389+
relations: ['cat'],
2390+
}
2391+
const query: PaginateQuery = {
2392+
path: '',
2393+
}
2394+
await catRepo.softDelete({ id: cats[0].id })
2395+
const result = await paginate<CatHomeEntity>(query, catHomeRepo, config)
2396+
expect(result.data[0].cat).not.toBeNull()
2397+
await catRepo.restore({ id: cats[0].id })
2398+
})
2399+
23852400
it('should return only undeleted items', async () => {
23862401
const config: PaginateConfig<CatEntity> = {
23872402
sortableColumns: ['id'],

src/paginate.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ export async function paginate<T extends ObjectLiteral>(
230230
}
231231
}
232232

233+
if (config.withDeleted) {
234+
queryBuilder.withDeleted()
235+
}
236+
233237
if (config.relations) {
234238
const relations = Array.isArray(config.relations)
235239
? OrmUtils.propertyPathsToTruthyObject(config.relations)
@@ -334,10 +338,6 @@ export async function paginate<T extends ObjectLiteral>(
334338
queryBuilder.andWhere(`(${baseWhereStr})`)
335339
}
336340

337-
if (config.withDeleted) {
338-
queryBuilder.withDeleted()
339-
}
340-
341341
if (config.searchableColumns) {
342342
if (query.searchBy && !config.ignoreSearchByInQueryParam) {
343343
for (const column of query.searchBy) {

0 commit comments

Comments
 (0)