@@ -6,7 +6,6 @@ import type {
66 FieldHasDefault ,
77 FieldIsArray ,
88 FieldIsDelegateDiscriminator ,
9- FieldIsDelegateRelation ,
109 FieldIsRelation ,
1110 FieldType ,
1211 ForeignKeyFields ,
@@ -60,7 +59,7 @@ import type {
6059import type { FilterKind , QueryOptions } from './options' ;
6160import type { ExtQueryArgsBase } from './plugin' ;
6261import type { ToKyselySchema } from './query-builder' ;
63- import type { GetSlicedFilterKindsForField , GetSlicedModels } from './type-utils' ;
62+ import type { GetSlicedFilterKindsForField , GetSlicedModels , ModelAllowsCreate } from './type-utils' ;
6463
6564//#region Query results
6665
@@ -1331,6 +1330,15 @@ type CreateFKPayload<Schema extends SchemaDef, Model extends GetModels<Schema>>
13311330 }
13321331> ;
13331332
1333+ type RelationModelAllowsCreate <
1334+ Schema extends SchemaDef ,
1335+ Model extends GetModels < Schema > ,
1336+ Field extends RelationFields < Schema , Model > ,
1337+ > =
1338+ GetModelFieldType < Schema , Model , Field > extends GetModels < Schema >
1339+ ? ModelAllowsCreate < Schema , GetModelFieldType < Schema , Model , Field > >
1340+ : false ;
1341+
13341342type CreateRelationFieldPayload <
13351343 Schema extends SchemaDef ,
13361344 Model extends GetModels < Schema > ,
@@ -1360,8 +1368,8 @@ type CreateRelationFieldPayload<
13601368 } ,
13611369 // no "createMany" for non-array fields
13621370 | ( FieldIsArray < Schema , Model , Field > extends true ? never : 'createMany' )
1363- // exclude operations not applicable to delegate models
1364- | ( FieldIsDelegateRelation < Schema , Model , Field > extends true ? 'create' | 'createMany' | 'connectOrCreate' : never )
1371+ // exclude create operations for models that don't allow create
1372+ | ( RelationModelAllowsCreate < Schema , Model , Field > extends true ? never : 'create' | 'createMany' | 'connectOrCreate' )
13651373> ;
13661374
13671375type CreateRelationPayload <
@@ -1715,10 +1723,8 @@ type ToManyRelationUpdateInput<
17151723 */
17161724 set ?: SetRelationInput < Schema , Model , Field , Options > ;
17171725 } ,
1718- // exclude
1719- FieldIsDelegateRelation < Schema , Model , Field > extends true
1720- ? 'create' | 'createMany' | 'connectOrCreate' | 'upsert'
1721- : never
1726+ // exclude create operations for models that don't allow create
1727+ | ( RelationModelAllowsCreate < Schema , Model , Field > extends true ? never : 'create' | 'createMany' | 'connectOrCreate' | 'upsert' )
17221728> ;
17231729
17241730type ToOneRelationUpdateInput <
@@ -1765,7 +1771,8 @@ type ToOneRelationUpdateInput<
17651771 delete ?: NestedDeleteInput < Schema , Model , Field , Options > ;
17661772 }
17671773 : { } ) ,
1768- FieldIsDelegateRelation < Schema , Model , Field > extends true ? 'create' | 'connectOrCreate' | 'upsert' : never
1774+ // exclude create operations for models that don't allow create
1775+ | ( RelationModelAllowsCreate < Schema , Model , Field > extends true ? never : 'create' | 'connectOrCreate' | 'upsert' )
17691776> ;
17701777
17711778// #endregion
0 commit comments