There are two different approaches to configuring a hierarchical relationship between two documents.
 

1. Add the children to the parent document

Content modeling

You can make it easy for editors to define child pages for a given entry. Modify the parent custom type:

  • Add a Group field
  • Add a Content Relationship field inside the group

This will allow you to add all the children documents you need for a given parent.

Retrieving the child pages

You can use the fetchLinks query option to grab the necessary fields to build the menu (e.g., title). 

You can read more about this in the Prismic developer docs:
Javascript, PHP, Node.js, React.js, Laravel, Ruby, Rest API

 
Alternatively you can take the group of links and create an array of the documents IDs. With this array of IDs you can query all the child documents.

Here is how you can query documents by their IDs:
Javascript, PHP, Node.js, React.js, Laravel, Ruby, Java, Rest API
 

2. Add the parent to the child document

Content modeling

To give a Child document a single parent, modify the child custom type:

  • Add a single Content Relationship field

This will allow you to specify a "Parent page" for a given child. 

 
To allow a child document to have multiple parents or categories, modify the child custom type:

  • Add a Group field
  • Add a Content Relationship field inside the group

This will allow you to add as many parents or categories for
 

Retrieving the child pages

Using this method you would be able to know which parent(s) a child document has as well being able to query all the children of a given parent.

To retrieve all the child documents for a given parent, query the child documents by their Content Relationship field you setup.

You can read more about how to do this in the Prismic developer docs:
Javascript, PHP, Node.js, React.js, Laravel, Ruby, Java, Rest API

Did this answer your question?