This is part two of our Directus Basics series. In part one, we set up a Directus instance and created our first collection. Today we're covering one of the most powerful features Directus offers: relationships between collections.
By the end of this article, you'll understand three core relationship types — Many to One (M2O), One to Many (O2M), and Many to Many (M2M). There's a fourth type, Many to Any (M2A), which we'll cover in a future post.
Continuing from our existing Directus instance, let's create a new collection called branding. Select all the additional default fields Directus offers.
| Field | Type | |---|---| | name | String (basic input) | | description | Text (textarea) |
Once the collection is set up, add a few entries — I'd recommend at least two different brands so you can see the relationship in action once it's wired up.
Logically: many products can belong to one brand. That's a Many to One relationship — many products, to one brand.
Steps: Create Field → Relational category → Many to One Key: brandid Related Collection: branding De-select Enable Create Button — you always want to choose a brand from an existing list, not create one on the fly Save
Since one brand can have many products, we need to set up the reverse relationship explicitly on the branding collection.
Steps: Create Field → Relational category → One to Many Key: products Related Collection: products Foreign Key: brandid — the field we just created on the products side De-select Enable Create Button Save
Go back into your products collection and assign a brand to each product. Make sure at least two products share the same brand so the relationship is visible.
You'll notice each product can only belong to one brand — that's the M2O relationship at work.
Now open the branding collection and click into one of your brands. You'll see the products you just assigned show up automatically — you didn't have to add them manually. Directus handled that because of the relationship you configured.
A common real-world example: tags on products, used to improve SEO. A single product can have multiple tags, and a single tag can apply to many products.
Back in the products collection: Create Field → Relational category → Many to Many Key: tags Related Collection: tags De-select Enable Create Button Do not save yet — scroll down and click "Continue in Advanced Field Creation Mode" In the sidebar, click Relationship, then find Corresponding Field Check "Create Field" — under Field Name, you should see products appear Save
Why the advanced flow? Under Corresponding Field, products appears automatically — that's Directus telling you it's about to create the matching relational field back on the tags collection. Unlike the M2O/O2M setup, you don't have to manually configure both sides — Directus builds the reverse relationship for you.
Now, when you add a tag to a product, Directus automatically links that product under the corresponding tag in the tags collection — no manual syncing required.
| Relationship | Direction | Example | |---|---|---| | M2O | Many records → one related record | Products → Branding | | O2M | One record → many related records | Branding → Products | | M2M | Many ↔ many, both directions | Products ↔ Tags |
Relationships are one of those Directus features that make a lot more sense once you've built one yourself than they do reading about them — so I'd recommend replicating this setup in your own instance before moving on.
