@@ -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 , ExtResultBase } 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
@@ -1351,6 +1350,15 @@ type CreateFKPayload<Schema extends SchemaDef, Model extends GetModels<Schema>>
13511350 }
13521351> ;
13531352
1353+ type RelationModelAllowsCreate <
1354+ Schema extends SchemaDef ,
1355+ Model extends GetModels < Schema > ,
1356+ Field extends RelationFields < Schema , Model > ,
1357+ > =
1358+ GetModelFieldType < Schema , Model , Field > extends GetModels < Schema >
1359+ ? ModelAllowsCreate < Schema , GetModelFieldType < Schema , Model , Field > >
1360+ : false ;
1361+
13541362type CreateRelationFieldPayload <
13551363 Schema extends SchemaDef ,
13561364 Model extends GetModels < Schema > ,
@@ -1380,8 +1388,8 @@ type CreateRelationFieldPayload<
13801388 } ,
13811389 // no "createMany" for non-array fields
13821390 | ( FieldIsArray < Schema , Model , Field > extends true ? never : 'createMany' )
1383- // exclude operations not applicable to delegate models
1384- | ( FieldIsDelegateRelation < Schema , Model , Field > extends true ? 'create' | 'createMany' | 'connectOrCreate' : never )
1391+ // exclude create operations for models that don't allow create
1392+ | ( RelationModelAllowsCreate < Schema , Model , Field > extends true ? never : 'create' | 'createMany' | 'connectOrCreate' )
13851393> ;
13861394
13871395type CreateRelationPayload <
@@ -1738,10 +1746,8 @@ type ToManyRelationUpdateInput<
17381746 */
17391747 set ?: SetRelationInput < Schema , Model , Field , Options > ;
17401748 } ,
1741- // exclude
1742- FieldIsDelegateRelation < Schema , Model , Field > extends true
1743- ? 'create' | 'createMany' | 'connectOrCreate' | 'upsert'
1744- : never
1749+ // exclude create operations for models that don't allow create
1750+ | ( RelationModelAllowsCreate < Schema , Model , Field > extends true ? never : 'create' | 'createMany' | 'connectOrCreate' | 'upsert' )
17451751> ;
17461752
17471753type ToOneRelationUpdateInput <
@@ -1788,7 +1794,8 @@ type ToOneRelationUpdateInput<
17881794 delete ?: NestedDeleteInput < Schema , Model , Field , Options > ;
17891795 }
17901796 : { } ) ,
1791- FieldIsDelegateRelation < Schema , Model , Field > extends true ? 'create' | 'connectOrCreate' | 'upsert' : never
1797+ // exclude create operations for models that don't allow create
1798+ | ( RelationModelAllowsCreate < Schema , Model , Field > extends true ? never : 'create' | 'connectOrCreate' | 'upsert' )
17921799> ;
17931800
17941801// #endregion
0 commit comments