Learn more about how Budibase creates row to row relationships
This section covers one of the more complex topics of your Budibase web app, the ability to create relationships between different rows. It is important to note that when a relation between two rows is formed these two particular rows become joined, rather than any particular fields in the rows being joined. The relationship is bi-directional, in that when it is created each row will have a relation to the other one. A row is also allowed to relate to many rows, meaning that many to many relationships can be created in your web app (if required).
The process of creating a relationship column allowing rows in two different tables to be linked is quite simple.
First, create/pick two tables that the relationship should be formed between.
Make sure that in both tables there is a column defined which can be used for display purposes, when creating this column make sure to set it with the Display column toggle.
Click the Create new column button in either of the two tables and select the Relationship data type from the dropdown.
This section covers how to create and update relationships in relation to the tables and you might be wondering how to actually use them. This is for a different topic and has been covered in the Design - relationships section.
In the next section, we will cover an example of relationships, how to build them, and the various types that can be modeled.
Building a relationship example
In this example, we will be creating a web app for tracking students, teachers, parking spots for teachers and classes in a school - specifically how they relate to each other.
Specifically, we are going to break these down into the three relationship types that can be modeled with Budibase. Below we will map out the relationships that we are going to create, first describing them then walking through how to build them.
The first relationship type we can model in Budibase is the most basic of types, linking two rows to each other. In this case, a Teacher is assigned a single parking spot and that parking spot can only be used by a single teacher.
The second relationship we can model in Budibase is one of the most common, linking a single row to many other rows. Here we can see that a class can only be taught by a single teacher however a teacher is capable of teaching many different classes.
The last relationship we can model is arguably one of the most complexes but again very common in real-life systems. Here we can see that students are able to take many classes and each class can have many different students in it.
To create this in Budibase all we need to do is:
Create the four tables, students, classes, teachers, and parking spots. In each of these, we will initially create a display text column and mark these as the Display column - for example, Name or Subject.
As you can see by creating three relationship columns we were able to make a fairly complex web of relationships, which can now be easily managed when creating/updating rows in any of the tables.
Based on the example above here is a video showing how easy it is to create in the Budibase Builder!