Data Model

Relationships

Leverage Directus relationships to create powerful data connections. Explore Many to One, One to Many, Many to Many, and Many to Any relationships, along with Translations for multilingual content management.

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)

2 tables: One for cities each of which has a reference to a country ID, and a country table

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.

A cities collection item with the country many-to-one relation set to the country "Chile"

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.

M2O Examples
  • Given cities and countries collections, many cities would be assigned to one country.
  • Given orders and customers, many orders would be assigned to one customer.
  • Given books and pubilshers, many books would be assigned to one publisher.

One to Many (O2M)

A one-to-many relation showing 2 tables: cities and countries

In a O2M relationship, one item from a collection is linked to multiple items in a different collection.

A one-to-many relation field being open

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)

A many-to-many relation showing 3 tables: recipes, ingredients and recipes-ingredients

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.

Self-Referencing M2M Examples
  • 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)

A series of tables, showing blog, content_builder, headings, images and text_bodies

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.

Read our tutorial on using a Builder (M2A) to create reusable page components.

Translations

An articles, languages and articles_translations table, linked by language_id

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.