@@ -390,8 +390,11 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
390
390
) ;
391
391
}
392
392
393
- // note that we can't call `createMany` directly because it doesn't support
394
- // nested created, which is needed for creating base entities
393
+ // `createMany` doesn't support nested create, which is needed for creating entities
394
+ // inheriting a delegate base, so we need to convert it to a regular `create` here.
395
+ // Note that the main difference is `create` doesn't support `skipDuplicates` as
396
+ // `createMany` does.
397
+
395
398
return this . queryUtils . transaction ( this . prisma , async ( tx ) => {
396
399
const r = await Promise . all (
397
400
enumerate ( args . data ) . map ( async ( item ) => {
@@ -423,17 +426,33 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
423
426
this . doProcessCreatePayload ( model , args ) ;
424
427
} ,
425
428
426
- createMany : ( model , args , _context ) => {
427
- if ( args . skipDuplicates ) {
428
- throw prismaClientValidationError (
429
- this . prisma ,
430
- this . options . prismaModule ,
431
- '`createMany` with `skipDuplicates` set to true is not supported for delegated models'
432
- ) ;
433
- }
429
+ createMany : ( model , args , context ) => {
430
+ // `createMany` doesn't support nested create, which is needed for creating entities
431
+ // inheriting a delegate base, so we need to convert it to a regular `create` here.
432
+ // Note that the main difference is `create` doesn't support `skipDuplicates` as
433
+ // `createMany` does.
434
434
435
- for ( const item of enumerate ( args ?. data ) ) {
436
- this . doProcessCreatePayload ( model , item ) ;
435
+ if ( this . isDelegateOrDescendantOfDelegate ( model ) ) {
436
+ if ( args . skipDuplicates ) {
437
+ throw prismaClientValidationError (
438
+ this . prisma ,
439
+ this . options . prismaModule ,
440
+ '`createMany` with `skipDuplicates` set to true is not supported for delegated models'
441
+ ) ;
442
+ }
443
+
444
+ // convert to regular `create`
445
+ let createPayload = context . parent . create ?? [ ] ;
446
+ if ( ! Array . isArray ( createPayload ) ) {
447
+ createPayload = [ createPayload ] ;
448
+ }
449
+
450
+ for ( const item of enumerate ( args . data ) ) {
451
+ this . doProcessCreatePayload ( model , item ) ;
452
+ createPayload . push ( item ) ;
453
+ }
454
+ context . parent . create = createPayload ;
455
+ delete context . parent [ 'createMany' ] ;
437
456
}
438
457
} ,
439
458
} ) ;
0 commit comments