๐Ÿ“ฆ directus / docs

๐Ÿ“„ 3.data-model.md ยท 47 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47---
title: Configure a Data Model
description: This guide will cover creating a collection in Directus via the Data Studio, creating fields, and configuring relationships.
navigation:
  label: Configure a Data Model
---

:video-embed{video-id="637aafa2-b323-4ad0-adf0-ba52328bb798"}

This guide will cover creating a collection in Directus via the Data Studio, creating fields, and configuring relationships.

:cta-cloud

## Creating a Collection

Log into the Directus Data Studio as an administrator. If this is a brand-new project, you will be presented with the option to create your first collection. Otherwise, go to the settings module and create a new collection from the Data Model page.

Set the name of this collection to be `posts`, leaving all other options in both the collection setup and optional field pages as their defaults. You now have a new collection with only a primary key.

![A brand new collection](/img/2e088221-6bc5-4c00-b348-e23f77a9a748.webp)

## Creating Fields

Your collection only has a primary key. From your new `posts` collection configuration page, click the **Create Field** button and select the Input interface. Set the key to `title` and leave all other options as their defaults.

Create another new field with a What You See Is What You Get (WYSIWYG) interface. Set the key to `content`.

## Configuring a Relationship

Create a new collection called `authors`. In the new collection, create a new field with an Input interface and set the key to `name`.

Go to the `posts` collection configuration and create a new field with the Many to One interface and set the key to `author`. Set the related collection to `authors` and configure the Display Template to show just the author's name by clicking :icon{name="material-symbols:add-circle-outline-rounded"} and selecting the `name` field.

Now that you have successfully configured a relationship between the two tables, you can start creating data.

In the module bar, go to the content module. Enter your `authors` collection and create 2 authors with the names `Ben Haynes` and `Rijk van Zanten`.

Enter the `posts` collection and create two posts, selecting an author from the Many to One interface.

![Selecting an item from a relation](/img/73e236ac-322f-4565-ba98-172a5596bcad.webp)

![Both collections' settings](/img/8a641c77-e13b-4bec-ae54-085a5484cd32.webp)

## Next Steps

Read more about configuring [collections](/guides/data-model/collections), [fields](/guides/data-model/fields), and [relationships](/guides/data-model/relationships). See all available [interfaces](/guides/data-model/interfaces) in Directus. Access your new collections via API or SDK using :product-link{product="connect"}.