-
QuestionWhen user is creating a For example I have a model model Project {
id String @id @default(uuid()) @db.Uuid
name String @db.VarChar(255)
body String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
userId String @db.Uuid
user User @relation(fields: [userId], references: [id])
tasks Task[]
} The generated type type Prisma.ProjectCreateInput = {
id?: string | undefined;
name: string;
body: string;
createdAt?: string | Date | undefined;
updatedAt?: string | Date | undefined;
user: Prisma.UserCreateNestedOneWithoutProjectsInput;
tasks?: Prisma.TaskCreateNestedManyWithoutProjectInput | undefined;
} I'll use {
id?: string | undefined;
name: string;
body: string;
createdAt?: string | Date | undefined;
updatedAt?: string | Date | undefined;
} My problem is I can't use So I need a type to pick out "scalar fields only". Is there a built-in type? How to reproduce (optional)No response Expected behavior (optional)No response Information about Prisma Schema, Client Queries and Environment (optional)No response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @vietan0 👋 Prisma does not provide a built-in type that includes only the non-relation scalar fields. However, you can create such a type yourself using TypeScript's utility types. For example, you can use the export type ProjectUncheckedCreateInput = {
id?: string
name: string
body: string
createdAt?: Date | string
updatedAt?: Date | string
userId: string
tasks?: TaskUncheckedCreateNestedManyWithoutProjectInput
} type ProjectScalarInput = Omit<ProjectUncheckedCreateInput, 'userId' | 'tasks'>; This will give you a type that includes only the non-relation scalar fields. You can use this type to validate your |
Beta Was this translation helpful? Give feedback.
Hi @vietan0 👋
Prisma does not provide a built-in type that includes only the non-relation scalar fields. However, you can create such a type yourself using TypeScript's utility types. For example, you can use the
Omit
utility type to remove the relation fields from theProjectUncheckedCreateInput
type:This will give you a type that includes only the non-relation scalar fiel…