Columns & RelationshipsLearn how to create columns and relationships between tables

Of of the more powerful features of teh Devize database is being able to created relationships between your data.

Think for a second, about building your own CRM. You'd have Companies, related to each company would be a list of contacts. You also might have an Deal, which is connected to a company and a contact.

Frame 1867.png

Creating Relationships

You can create relationships the same way you create a regular column, but instead of picking a basic type (text, number, true/false) pick the name of another table in your app.

Something unique to relationship though, is that you will need to fill out the settings for your relationship

Frame 1868.png

Relationship Type

Each Relationship can be one-to-one or one-to-many. one-to-many are more common. If you are not familiar with these terms, its easiest to learn them through example

One to one - Lets say you'd like every user in your app to have a public profile. While you could add all the fields for their profile directly to the user table, it may be cleaner to create a new profile table and add the fields to that. Each user would have one profile, hence the name one-to-one

One to many - Lets day you wants to let users create comments on a post. You would create a comments table and add a one-to-many relationship to the post table. One post would have Many comments

A quick note about Many to Many relationships - sometimes you need to create a relationship that could be thought of as Many to Many, like school where a class has many students and students have many classes on their schedule. The solution is to create what some call a join table. In the school example, you might make a table called enrollment, that has a one to many relationship with students and a one to many relationship with classes.

Related Field Name

When you create a relationship, we create fields on both related tables. this lets you name what the column should be called in the table you are adding the relationship to. In the posts/comments example above, if I was adding a relationship between the comments table and a post, I would call the comment column "Post" and then in the Related Field Name, I would probably call it something like "comments" since posts columns will be a list of comments

When Reference Value Deleted

When working with relationships, there can be a question about what do to when the row you are relating to get deleted. Consider the User/Profile feature we talked about in the one to one example above. If the user were to delete their account, I can make it so the related profile row gets set to empty, or I have have the row be deleted automatically.

Published 01/10/2025Last updated 03/10/2025