File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff 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' ] ,
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments