We use relations extensively in our systems to help us build structured data.
Let's say you have two databases for your theoretical business 😉
- One that tracks customers
- One that tracks items purchased
You want to know both which customers bought which items, as well as which items were purchased by which customers. This is a job for relations!
- In the two tables above, the columns labeled
↗ Items Purchased
and↗ Customers
are relation properties, which can be added like any other database property.
- Here, when you add an item bought into the Customers database, the customers who bought them automatically appear in the
↗ Customers
column in the Items database.
Example use cases
- Connect your database of restaurants with your database of neighborhoods so you can see which restaurants are in which neighborhoods at a glance.
- Connect your database of meeting notes with your database of clients to provide quick access to the notes relevant to each client.
- Connect your database of tasks with your database of bigger projects to understand how projects are broken down into tasks, and how tasks contribute to projects.
- Connect your database of candidates with your database of interviewers to keep track of who interviewed whom.
Create a relation
To relate two databases, you need two databases. So let's assume you've made the Customers and Items databases above for the purpose of this walkthrough.
- Add a new column/property to your Customers database.
- In the property menu, give it a name in the box provided, like
Items Purchased
.
- Choose
Relation
from theType
menu.
- You'll be asked to find the database you want to create the relation with. You can use the input at the top to search for this database.
- You'll see a preview of the relation. In this case, we've created a relation from the Customer database to the Items database.
- Click the blue
Add relation
button to finalize the creation of the new relation property.
- Now when you click in a cell in this relation column, you'll bring up a menu where you can search for and choose items from the other database to add.
- For example, this is how you can add which clothes each customer bought.
- To add multiple items at once, click the name of the item. To delete an item, hover over and then click the
–
button on the right.
Relation
as the property type for that particularly property. You'll be prompted to choose a new database.Two-way relations
Relations are created as one-way by default. But you can easily toggle on a corresponding relation in the destination database.
With two-way relations, the edits work both ways! So if you add a customer to the Items database in the relation column, the change pops up in your Customers database.
- Follow the above instructions to create a new relation property.
- Click the toggle that says
Show on [name of related database]
. In our example, this saysShow on Items DB
.
- Give this corresponding relation a name.
- Below, you'll see a preview of the two-way relation. In this case, we've created a relation from the Customer database to the Items database, and a relation from the Items database to the Customer database.
- Click the blue
Add relation
button to finalize the creation of these two new relation properties.
View and remove related pages
When you create a relation, you're essentially adding Notion pages stored in one database into the property field of another.
- These pages can be opened and edited like any other! Click on the page in the relation column. Then click on it again in the window that pops up.
- You can also remove any related page by hovering over and clicking the
–
at the right.
📹 Self-uploaded videos are not supported yet. Please use a third party video provider such as Youtube, Wistia or Vimeo.
- You can choose to limit the number of pages that can be included in your relations property – with the option to select
1 page
or to haveNo limit
.
- If you select the option to limit it to
1 page
, people using your database will only be able to select 1 page in the relation. This is especially useful for situations where only one page should be related to one another, for example - if only one order number should be associated with each purchase.
Relate a database to itself
Let's say you want items in the same database to have relationships with each other. For example, you have a tasks database and you want each task to relate to other tasks.
- Start off by creating a new relation.
- Then search for and choose the database you're currently working in.
- You'll now see that the database is related to
This database
.
Just as with relations between two databases, you can choose to make this a one-way relation or two-way relation.
- To make it a two-way relation, toggle on
Separate properties
. You'll see a second property show up.