Relations are where the magic of graph networks shine. The more models you have that reference other models, the more flexibility you have in representing a complete picture of your data.
Each model can be connected to any other model through one of three relation types:
- Many to One
Example: Product to Producer. A producer can have many products, but a product has one producer.
- One to Many
Example: Producer to Product. A producer can have many products, but a product has one producer.
- Many to Many
Example: Consumer to Product. A consumer can consume many products, and a product can be consumed by many consumers.
Additionally, a relation can be of one or more types. This is known as Union Types in GraphQL.
You can read more about using Union Types in GraphCMS here.
Relations can also benefit from editorial sorting, independent from a derived property.
Sorting alphabetically, by date or other data values is a derived sort order. Sometimes you simply want to manually tell a relationship which order to represent the values.
Working with Relations
Connecting a Relation
- Open a content entry you'd like to connect a relation to.
- Locate the relation field.
- Choose between "add an existing..." or "create and add a new..." of whatever model you are wanting to connect.
- When pressing on:
- "Add an existing"
- A popup listing all the possible entries of that model will appear.
- Press the link icon at the far left of the content entry.
- "Create and add new"
- An in-line content editor window for the selected type will appear.
- Fill out for the form's fields.
- Choose to "save" or "save and publish" to create a
PUBLISHEDentry in the related model. Connecting will happen automatically.
- "Add an existing"
Connecting Multiple Types to a Relation
Follow the steps from "Connecting a Relation", when you press on either of the buttons, an intermediate select box will have you first decide with model you want to choose from or create a new entry in.
Disconnecting a Relation
- Open a content entry you'd like to disconnect a relation to.
- Find the relation field you'd like to remove a conenction from.
- Click on the broken link icon at the far right of the content entry.
Sorting a Relation
- Open a content entry you'd like to sort relations on.
- Find the relation field you'd like to sort.
- Grab the four dot handle at the left edge of the content entry and drag up and down in the list.
Were you expecting something more?
We are constantly contributing to our documentation, but if you spot something we're missing, let us know and we'll be sure to add it.