Relationships
Directus supports all standard relationship types, as well as a few more of its own compound types, meant to streamline certain common configurations.
Many to One (M2O)
In a M2O relationship, multiple items from the one collection are linked to one item in a different collection. One field is added to the 'many' collection referencing the primary key of the 'one' collection.
In Editor, having a M2O field does not automatically provide navigation to the related collection's items. To achieve this, the related collection requires a One to Many field to be set up.
- Given
cities
andcountries
collections, many cities would be assigned to one country. - Given
orders
andcustomers
, many orders would be assigned to one customer. - Given
books
andpubilshers
, many books would be assigned to one publisher.
One to Many (O2M)
In a O2M relationship, one item from a collection is linked to multiple items in a different collection.
Creating a O2M interface on the 'many' side of a M2O relationship creates an Alias
field, which lets us access related items. This does not create a new database column as the O2M field is purely virtual. It creates an interface within the Editor to access items from an O2M perspective.
Many to Many (M2M)
In a M2M relationship, an additional collection is created known as the junction collection. The junction collection stores the primary keys from two related collections, allowing for any number of items to be related between two collections.
You can also have a self-referencing M2M relationship that connects items in the same collection.
- Given an
articles
collection, you could configure related articles. - Given a
users
collection, you could configure a friends list. - Given
papers
, you could configure citations.
One example is "Related Articles", where each article relates to many other articles.
Many to Any (M2A)
In a M2A relationship, one collection can be related to any item in any collection. This is sometimes known as a matrix field or replicator.
When you configure a M2A in Directus, a M2A Alias
field is created as well as a junction collection. The junction collection in a M2A relationship also stores the collection name for related collections.
Translations
When you create a Translations interface in Directus, a translations O2M Alias
field is created, as well as a languages
collection and a junction collection between your main collection and languages
. All translated text is stored in the junction collection.