PayloadCMS Relationship, Upload, and Join Fields Explained
Learn all about Payload CMS collections
In this guide, we’re going to go over relationship fields in PayloadCMS. Let’s dive in.
In the two previous guides, we’ve gone over many of the fields available to us in Payload CMS. Some of these are data fields that store data in your database, and others are presentational fields that simply help you organize your admin panel but don’t save data to your database.
We’ve talked about the main fields you’ll use in most projects, a few layout fields that help you organize and group your data, and now we’ll round off all this talk about Payload CMS fields with relationship fields.
There are three fields that I’d like to discuss today: relationship, upload, and join. The relationship and upload fields are data fields, while the join field is a presentational field. These fields could be considered what I call a main field, but each of these fields is more involved than the main fields we already discussed. So, it makes sense to group these in their own guide.
Relationship field
The relationship field allows you to relate documents together. A good example of this is to have an author field within a post collection. You can have a collection of blog authors then, using a relationship field in your blog entry, assign that author to their respective blog post.
In order to render the relationship on the frontend, you may need to adjust the depth at which you are querying your database. Typically, a depth of 1 will be enough, but if you’re only seeing an id when you request a relationship from your database, you will want to increase the depth.