Return Type With Relations
Hello there,
I have a quick question about return type with relation. If I have this sort of query:
So should Prisma's type have a customer as a return type?
If it is, why does it always crying that the customer is not a part of the type of loan?
4 Replies
Hi @Arthur 👋
When you use
include
option in a query, the return type should indeed include the related fields specified in the include
clause.
Can you share how you are using it in your code?Sure,
Usage of the method:
The error:
It's only works when I create the type by myself:
Thank you for sharing. To address your issue, you can use Prisma Validator API to resolve this issue. Look at my example implementation
You can now use the
findLoanDetails
method
Prisma validator | Prisma Documentation
The Prisma validator is a utility function that takes a generated type and returns a type-safe object which adheres to the generated types model fields.
Thank you for your answer, I'll read more about this include your approach.