@@ -515,15 +515,11 @@ export function enhance(prisma: any, context?: EnhancementContext<${authTypePara
515
515
return source ;
516
516
}
517
517
518
- private removeCreateFromDelegateInput (
519
- typeAlias : TypeAliasDeclaration ,
520
- delegateModels : DelegateInfo ,
521
- source : string
522
- ) {
518
+ private removeCreateFromDelegateInput ( typeAlias : TypeAliasDeclaration , delegateInfo : DelegateInfo , source : string ) {
523
519
// remove create/connectOrCreate/upsert fields from delegate's input types because
524
520
// delegate models cannot be created directly
525
521
const typeName = typeAlias . getName ( ) ;
526
- const delegateModelNames = delegateModels . map ( ( [ delegate ] ) => delegate . name ) ;
522
+ const delegateModelNames = delegateInfo . map ( ( [ delegate ] ) => delegate . name ) ;
527
523
const delegateCreateUpdateInputRegex = new RegExp (
528
524
`^(${ delegateModelNames . join ( '|' ) } )(Unchecked)?(Create|Update).*Input$`
529
525
) ;
@@ -538,17 +534,24 @@ export function enhance(prisma: any, context?: EnhancementContext<${authTypePara
538
534
return source ;
539
535
}
540
536
541
- private readonly ModelCreateUpdateInputRegex = / ( \S + ) ( U n c h e c k e d ) ? ( C r e a t e | U p d a t e ) .* I n p u t / ;
542
-
543
537
private removeDiscriminatorFromConcreteInput (
544
538
typeAlias : TypeAliasDeclaration ,
545
- _delegateInfo : DelegateInfo ,
539
+ delegateInfo : DelegateInfo ,
546
540
source : string
547
541
) {
548
542
// remove discriminator field from the create/update input because discriminator cannot be set directly
549
543
const typeName = typeAlias . getName ( ) ;
550
544
551
- const match = typeName . match ( this . ModelCreateUpdateInputRegex ) ;
545
+ const delegateModelNames = delegateInfo . map ( ( [ delegate ] ) => delegate . name ) ;
546
+ const concreteModelNames = delegateInfo
547
+ . map ( ( [ _ , concretes ] ) => concretes . flatMap ( ( c ) => c . name ) )
548
+ . flatMap ( ( name ) => name ) ;
549
+ const allModelNames = [ ...new Set ( [ ...delegateModelNames , ...concreteModelNames ] ) ] ;
550
+ const concreteCreateUpdateInputRegex = new RegExp (
551
+ `^(${ allModelNames . join ( '|' ) } )(Unchecked)?(Create|Update).*Input$`
552
+ ) ;
553
+
554
+ const match = typeName . match ( concreteCreateUpdateInputRegex ) ;
552
555
if ( match ) {
553
556
const modelName = match [ 1 ] ;
554
557
const dataModel = this . model . declarations . find (
0 commit comments