I'm using Prisma new project. I've Category recursive relation :
model Category {
id Int @id @default(autoincrement())
name String
children Category[] @relation("CategoryToCategory")
parentId Int?
parent Category? @relation(fields: [parentId], references: [id])
}
This relation work nice, but for get all categories with all children (full tree, not only 1 level), i don't know if it's possible with Prisma ? It's generally called eager loading.
With this request, i get only first children, but i would like get very all tree, do you know if it's possible ?
const allCategories = await db.category.findMany({
include: {
parent: true, // return only first level
children: true, // return only first level
},
})
Thank you !