When working with a many-to-many relationship between Post and Upload in Prisma, I encountered an issue where Prisma was assigning the type 'never' to upload.posts. This prevented me from querying the relationship I needed. It seems unclear why Prisma would assign this type. Below is the findFirst statement I attempted to use to connect an upload to a post:
await prisma.upload.findFirst({
where: {
id: upload.id,
},
select: {
type: true,
},
// Prisma states that posts is of Type never
posts: {
connect: {
id: post.id
}
}
});
Below is the schema for the relationships:
model Upload {
id Int @id @default(autoincrement())
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
uploads Upload[]
}