Relation not included in the generated types
Hello,
I have the following model, generated from a database-first approach.
The query:
...returns the following data:
Unfortunately, the generated Prisma type does not include the relation "projects". This means, the following typing does not include the relation.
const entries: Entry[] = await prisma.entry.findMany({ ... })
Any idea why that is?11 Replies
can you run Prisma generate and try restarting your IDE?
I did, but it doesn't change anything.
Could this be a "works as designed"? Sounds very much like this when looking at the docs: https://www.prisma.io/docs/orm/prisma-client/type-safety/operating-against-partial-structures-of-model-types
Operating against partial structures of your model types | Prisma D...
This page documents various scenarios for using the generated types from the Prisma namespace
ooh wait sorry I completely misread your question
so if you want to manually type this you can do
Prisma.EntryGetPayload<{include:{projects:true}}>
Could you please provide the complete code line? Not sure exactly what you mean. Thanks man!
Ahh, I see... do you mean?
const entries: Prisma.EntryGetPayload<{ include: { projects: true } }>[] = await prisma.entry.findMany({ ... })
yup
altho FWIW if you're really just doing that I don't see why you'd type it yourself instead of getting the type from the return from findMany
So you are saying I shouldn't type
const entries
myself and just keep it as const entries = await prisma.entry.findMany({ ... })
?yes
There are some differing opinions about the extend of this but I personally almost always let TS infer types (so don't type things myself) whenever it's possible
And you still get code completion if it's typed automatically?
yes
Ohh that's great! Thank you very much