The Relation field is used to define a relationship with another content type which must be a collection type.
For example, when adding entries for the ‘Product’ content type, you might want to relate it to the ‘Dealers’ content type so you can get the list of dealers who are providing the same product, and when you go to the dealer’s page, you can see the list of products they are providing.
Adding this field to a Content Type
- Read this article on how to add a field.
- Select the type of relationship that you want to establish.
- One to One - Content type A has and belongs to one Content type B
- One to Many - Content type A has and belongs to many Content type B
- Many to One - Content type B has many Content type A
- Many to Many - Content type A has and belongs to many Content type B
- Select the other content type with which you want to establish this relationship.
- Configure other options like making this field private, then click on the Save button to apply changes.
When you add this field to a content type, then a widget named Relation is added to both the content types, where you can select the values of the other content type with which you defined the relation. The number of values you can select depends on the relationship configured.
There are basically 4 types of relations:
- One to One - Content type A has and belongs to one Content type B
- One to Many - Content type A belongs to many Content type B
- Many to One - Content type B has many Content type A
- Many to Many - Content type A has and belongs to many Content type B
Let’s understand each one in brief detail.
One to One
This relationship is very straightforward: there can be only one value in the relation field for the value of another content type.
For example, Product and Model share one to one relationship, i.e., the product has and belongs to one model. You will see that a product will have only one ‘Model Name’ value and vice versa.
Creating such a relation would allow you to relate one value with another value between the collection types.
One to Many
The relationship states that a value of a content type can belong to many values of another content type, but this is not true otherwise.
For example, ‘Customer’ and ‘Order’ share a one-to-many relationship, i.e., the customer belongs to many orders. You will see multiple values of orders for a customer, but when you check the order detail page, you will see that the order belongs to only one customer.
Creating such a relation would allow you to relate one value with multiple values of other collection types.
Many to One
This is the opposite of a one-to-many relationship. It states that many values of a content type can be related to a single value of another content type.
For example, Product and Brand share a many-to-one relationship, i.e., the brand has many products. When you open the product page, you will see that it has a brand value, but when you go to the brand page, you will see many products have that brand value.
Many to Many
This relationship is a combination of a one-to-many and a many-to-one relationship. It states that a value of a content type can be related to many other values of another content type and vice versa.
For example, Order and Product share a many-to-many relationship, i.e., the order has and belongs to many products. You will see that an order can have multiple products, and a product can belong to multiple orders.