0

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.

This is what I want enter image description here

So far in my code, I have a model that looks like this.

enter image description here

I don't understand how can I make an unlimited about of pages related to pages

Millenial2020
  • 2,465
  • 9
  • 38
  • 83
  • Does this answer your question? [many-to-many relationship in database design](https://stackoverflow.com/questions/1273715/many-to-many-relationship-in-database-design) – philipxy Sep 22 '22 at 06:01
  • Does this answer your question? [What are the options for storing hierarchical data in a relational database?](https://stackoverflow.com/questions/4048151/what-are-the-options-for-storing-hierarchical-data-in-a-relational-database) – user4157124 Sep 22 '22 at 20:13
  • [Why should I not upload images of code/data/errors when asking a question?](https://meta.stackoverflow.com/q/285551/3404097) [Why are images of text, code and mathematical expressions discouraged?](https://meta.stackexchange.com/q/320052/266284) – philipxy Sep 23 '22 at 05:46

1 Answers1

1

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")
}
some-user
  • 3,888
  • 5
  • 19
  • 43