---
description: >-
  Relationships between entities reflect how data models interact with each
  other, similar to relationships between tables in a relational database.
---

# Relationships

**Types of Relationships**:

* **One-to-One**: A relationship where a single record in one entity is associated with a single record in another. For instance, a user and a user profile.
* **One-to-Many**: A common relationship where a record from one entity can be associated with multiple records in another. For example, a single customer having multiple orders.
* **Many-to-Many**: This involves two entities that can have multiple records related to multiple records in the other entity. Many-to-many relationships often require a join table or entity.
* **Defining Relationships**: When defining a relationship, select the type of relationship, specify the related entities, and if necessary, define the join entity for many-to-many relationships.



In API Builder, by March 7, 2024 we have implemented support for creating **"one-to-many"** relationships between entities. This type of relationship allows one entity to be associated with multiple records of another entity, widely used for modeling hierarchical and related data in applications.

#### How to Create a "One-to-Many" Relationship

<figure><img src="https://1148960362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoUr44V66wfGLpZcCVHVL%2Fuploads%2FqFT3kfI2U8QAT0wljugd%2FScreenshot%202024-03-07%20at%2014.27.37.png?alt=media&#x26;token=b028c1e0-afcd-4832-acfb-a8eb513ba625" alt=""><figcaption></figcaption></figure>

1. Select the Target Entity: In the API Builder interface, select the entity for which you want to create a relationship. (target reference not a source)
2. Go to Relationships tab
3. Click 'Add a Relationship' button&#x20;
4. Fill out the form&#x20;



<figure><img src="https://1148960362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoUr44V66wfGLpZcCVHVL%2Fuploads%2Fvj4q2atXxkX675Iw0w2C%2FRelationship%20blanc.png?alt=media&#x26;token=89f99948-a658-4c74-bd04-029cfe1464c3" alt=""><figcaption></figcaption></figure>

5. Save the Relationship: After configuring the relationship parameters, save the changes. API Builder will automatically update the entity models and generate the corresponding API endpoints for managing the related data.

For example: In the "Source" field, enter "List". For "Source Reference", enter "List", and for "Target Reference", use "Tasks" (plural). This configuration establishes a "one-to-many" relationship between the "List" and "Task" entities, indicating that one "List" can contain multiple "Tasks".

<figure><img src="https://1148960362-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoUr44V66wfGLpZcCVHVL%2Fuploads%2Fp6DsPIPkPcEezJv9Y9ye%2Flist%20relationship%20update.png?alt=media&#x26;token=28f7c26e-65b1-43bd-99f3-6b378d90658c" alt=""><figcaption></figcaption></figure>



**Source primary** and **Source optional** checks&#x20;

**How to update the Relationship**&#x20;
