So I want to create a Sidebar similar to Notion where you can make a Page with a relationship where it can have multiple subpages. I have no idea where even to start.
So far in my code, I have a model that looks like this.
I don't understand how can I make an unlimited about of pages related to pages
CodePudding user response:
Sounds like you need a one-to-many relationship to the same object. You can do that, by adding an optional parentId
and then defining the relationship:
model Page {
id String @id
title String
// ...
parentId String?
parentPage Page? @relation(fields: [parentId], references: [id], name: "pageHierarchy")
childPages Page[] @relation(name: "pageHierarchy")
}