Skip to content

Commit

Permalink
fix: move the queryBuilder to enable withDeleted #973 (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
egg- authored Feb 18, 2025
1 parent 606bc25 commit 92d26ba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/paginate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,21 @@ describe('paginate', () => {
await catRepo.restore({ id: cats[0].id })
})

it('should return all relation items even if deleted', async () => {
const config: PaginateConfig<CatHomeEntity> = {
sortableColumns: ['id'],
withDeleted: true,
relations: ['cat'],
}
const query: PaginateQuery = {
path: '',
}
await catRepo.softDelete({ id: cats[0].id })
const result = await paginate<CatHomeEntity>(query, catHomeRepo, config)
expect(result.data[0].cat).not.toBeNull()
await catRepo.restore({ id: cats[0].id })
})

it('should return only undeleted items', async () => {
const config: PaginateConfig<CatEntity> = {
sortableColumns: ['id'],
Expand Down
8 changes: 4 additions & 4 deletions src/paginate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ export async function paginate<T extends ObjectLiteral>(
}
}

if (config.withDeleted) {
queryBuilder.withDeleted()
}

if (config.relations) {
const relations = Array.isArray(config.relations)
? OrmUtils.propertyPathsToTruthyObject(config.relations)
Expand Down Expand Up @@ -334,10 +338,6 @@ export async function paginate<T extends ObjectLiteral>(
queryBuilder.andWhere(`(${baseWhereStr})`)
}

if (config.withDeleted) {
queryBuilder.withDeleted()
}

if (config.searchableColumns) {
if (query.searchBy && !config.ignoreSearchByInQueryParam) {
for (const column of query.searchBy) {
Expand Down

0 comments on commit 92d26ba

Please # to comment.