Replies: 2 comments
-
Okay, it seems like I got it to work. I needed to use just select
However, now I have 2 further questions.
|
Beta Was this translation helpful? Give feedback.
-
Hi @Tanavya 👋
The original method you attempted, which included both When you used both In contrast, when you used only the const userArgs = Prisma.validator<Prisma.UserDefaultArgs>()({
select: { email: true, name: true, posts: true },
}); You explicitly specified the fields you wanted to include in the generated type, which ensured that only those fields were included and that the
If you want to create a type where some fields are optional and can also include relations, you would have to manually create these types in your application code. Here's an example: type PartialUser = Partial<Prisma.UserCreateInput & {{
posts: Prisma.PostCreateNestedManyWithoutAuthorInput;
}}>; In this example, |
Beta Was this translation helpful? Give feedback.
-
Question
Following this guide https://www.prisma.io/docs/orm/prisma-client/type-safety/operating-against-partial-structures-of-model-types. I implement the following:
Basically I want a
UserInputData
type which can easily be passed into my create user function, which also creates other relations. But I don't want to have to pass in all fields, for instance id, createdAt, updatedAt, etc which can be initiated by default.However, for some reason the
UserInputData
type I create with the code above actually includes all the fields, as if specifyingselect
had no effect on it. I think I could do some kind of hacky solution to combine the selected fields with the type generated with just include, but I was wondering if there is a better way to do what I want natively in Prisma. Is there a way to get this to work?Beta Was this translation helpful? Give feedback.
All reactions