@@ -1205,34 +1205,36 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
1205
1205
1206
1206
const cascadeDeletes : Array < { model : string ; entity : any } > = [ ] ;
1207
1207
const fields = getFields ( this . options . modelMeta , model ) ;
1208
- for ( const fieldInfo of Object . values ( fields ) ) {
1209
- if ( ! fieldInfo . isDataModel ) {
1210
- continue ;
1211
- }
1208
+ if ( fields ) {
1209
+ for ( const fieldInfo of Object . values ( fields ) ) {
1210
+ if ( ! fieldInfo . isDataModel ) {
1211
+ continue ;
1212
+ }
1212
1213
1213
- if ( fieldInfo . isRelationOwner ) {
1214
- // this side of the relation owns the foreign key,
1215
- // so it won't cause cascade delete to the other side
1216
- continue ;
1217
- }
1214
+ if ( fieldInfo . isRelationOwner ) {
1215
+ // this side of the relation owns the foreign key,
1216
+ // so it won't cause cascade delete to the other side
1217
+ continue ;
1218
+ }
1218
1219
1219
- if ( fieldInfo . backLink ) {
1220
- // get the opposite side of the relation
1221
- const backLinkField = this . queryUtils . getModelField ( fieldInfo . type , fieldInfo . backLink ) ;
1222
-
1223
- if ( backLinkField ?. isRelationOwner && this . isFieldCascadeDelete ( backLinkField ) ) {
1224
- // if the opposite side of the relation is to be cascade deleted,
1225
- // recursively delete the delegate base entities
1226
- const relationModel = getModelInfo ( this . options . modelMeta , fieldInfo . type ) ;
1227
- if ( relationModel ?. baseTypes && relationModel . baseTypes . length > 0 ) {
1228
- // the relation model has delegate base, cascade the delete to the base
1229
- const relationEntities = await db [ relationModel . name ] . findMany ( {
1230
- where : { [ backLinkField . name ] : where } ,
1231
- select : this . queryUtils . makeIdSelection ( relationModel . name ) ,
1232
- } ) ;
1233
- relationEntities . forEach ( ( entity ) => {
1234
- cascadeDeletes . push ( { model : fieldInfo . type , entity } ) ;
1235
- } ) ;
1220
+ if ( fieldInfo . backLink ) {
1221
+ // get the opposite side of the relation
1222
+ const backLinkField = this . queryUtils . getModelField ( fieldInfo . type , fieldInfo . backLink ) ;
1223
+
1224
+ if ( backLinkField ?. isRelationOwner && this . isFieldCascadeDelete ( backLinkField ) ) {
1225
+ // if the opposite side of the relation is to be cascade deleted,
1226
+ // recursively delete the delegate base entities
1227
+ const relationModel = getModelInfo ( this . options . modelMeta , fieldInfo . type ) ;
1228
+ if ( relationModel ?. baseTypes && relationModel . baseTypes . length > 0 ) {
1229
+ // the relation model has delegate base, cascade the delete to the base
1230
+ const relationEntities = await db [ relationModel . name ] . findMany ( {
1231
+ where : { [ backLinkField . name ] : where } ,
1232
+ select : this . queryUtils . makeIdSelection ( relationModel . name ) ,
1233
+ } ) ;
1234
+ relationEntities . forEach ( ( entity ) => {
1235
+ cascadeDeletes . push ( { model : fieldInfo . type , entity } ) ;
1236
+ } ) ;
1237
+ }
1236
1238
}
1237
1239
}
1238
1240
}
0 commit comments