How do you work with One-to-One or One-to-Many relationships in Hypi?
The example in this tutorial will answer this question.
Hypi’s low code platform supports the following two types of relationships between two entities (tables).
- One-to-One relationship
- One-to-Many relationship
We commonly see One-to-Many relationships examples in data-driven applications.
In one-to-many relationships, a single record in a table(entity) gets referenced by many records in another table (entities).
Then, what is a One-to-One relationship?
A single record in one table (entity) gets referenced by exactly one record in another table (entity).
Let’s deep dive into using one-to-one and one-to-many relationships in Hypi’s low code platform!
In this example, we will use the below schema.
type Profile {
userAccnt: Account @computed
(query: "hypi.id = '${self.hypi.createdBy}'")
address: Address
friends: [Account!]
}
This is a profile of a user of a social media platform. Now, we will check the usage of one-to-one and one-to-many relationships using the above schema.
*Please note Address and Account are the in-built core tables provided by Hypi.
Here is the ER diagram of the schema for better understanding