@@ -480,9 +480,15 @@ export function slugifyString(str: string): string {
480480 . replace ( / [ ^ a - z 0 - 9 - _ ] / g, '-' ) ;
481481}
482482
483- export async function cascadeChildrenDelete ( resource : AdminForthResource , primaryKey : string , context : { adminUser : any , response : any } , adminforth : IAdminForth ) : Promise < { error : string | null } > {
483+ export async function cascadeChildrenDelete ( resource : AdminForthResource , primaryKey : string , context : { adminUser : any , response : any } , adminforth : IAdminForth , visitedResources : Set < string > = new Set ( ) ) : Promise < { error : string | null } > {
484484 const { adminUser, response } = context ;
485485
486+ if ( visitedResources . has ( resource . resourceId ) ) {
487+ return { error : null } ;
488+ }
489+
490+ visitedResources . add ( resource . resourceId ) ;
491+
486492 const childResources = adminforth . config . resources . filter ( r => r . columns . some ( c => c . foreignResource ?. resourceId === resource . resourceId ) ) ;
487493
488494 for ( const childRes of childResources ) {
@@ -495,11 +501,13 @@ export async function cascadeChildrenDelete(resource: AdminForthResource, primar
495501 const childRecords = await adminforth . resource ( childRes . resourceId ) . list ( Filters . EQ ( foreignColumn . name , primaryKey ) ) ;
496502
497503 const childPk = childRes . columns . find ( c => c . primaryKey ) ?. name ;
498- if ( ! childPk ) continue ;
499504
500505 if ( strategy === 'cascade' ) {
501506 for ( const childRecord of childRecords ) {
502- const childResult = await cascadeChildrenDelete ( childRes , childRecord [ childPk ] , context , adminforth ) ;
507+ const childResult = await cascadeChildrenDelete ( childRes , childRecord [ childPk ] , context , adminforth , visitedResources ) ;
508+ if ( childResult ?. error ) {
509+ return childResult ;
510+ }
503511 const deleteChild = await adminforth . deleteResourceRecord ( { resource : childRes , record : childRecord , adminUser, recordId : childRecord [ childPk ] , response} ) ;
504512 if ( deleteChild . error ) return { error : deleteChild . error } ;
505513 if ( childResult ?. error ) {
0 commit comments