# Step 2: Create a “1 to Many” relation

* To create a 1 to Many relation between the Customers and Activities entities, go to the Entities page and open the settings for the Entity “UserName\_Acc\_customers”.&#x20;
* To define the relations in the Entity “UserName\_Acc\_customers”, click on the “Relations” tab.

{% embed url="<https://media.langstack.com/documentation/media/images/code/training_manual/chapter_5/ch5ex1activrelationstab.png>" %}

* To create a new relation, click on the \[+ Relation] button.

{% embed url="<https://media.langstack.com/documentation/media/images/code/training_manual/chapter_5/ch5ex1addrelation.png>" %}

* To create a one-to-many (1-to-M) relation between “UserName\_Acc\_customers” and “UserName\_Acc\_Activities”:&#x20;
  1. Enter Relation Name “Customer\_Activities”.&#x20;
  2. Select Relation as “One-to-Many”.&#x20;
  3. Select Related Entity as “UserName\_Acc\_Activities”. This relation defines that “UserName\_Acc\_customers” will be the parent Entity and “UserName\_Acc\_Activities” is the child Entity. One record in the parent Entity can be associated with multiple or many records in the child Entity.&#x20;
  4. “Customer\_ID” is selected by default from “UserName\_Acc\_customers” as it contains the primary key.&#x20;
  5. Select “Customer\_ID” in related entity “UserName\_Acc\_Activities”. Points (4) and (5) indicate that the relation is established based on the common field “Customer\_ID” for both entities. Relations are defined through the entity's primary keys only.&#x20;
  6. Select “Cascade delete”. This option indicates that if a record in the parent entity (on the left-hand side of the relation) is deleted, then the corresponding related records in the child entity (on the right-hand side of the relation) will automatically be deleted. No orphan child records remain when the parent entity record is deleted.

{% embed url="<https://media.langstack.com/documentation/media/images/code/training_manual/chapter_5/ch5ex1custactivitiesrel.png>" %}

* To save the fields, click the \[Save] button.

<figure><img src="https://media.langstack.com/documentation/media/images/code/training_manual/chapter_5/ch5saveentity.png" alt=""><figcaption></figcaption></figure>

* To finish, click the \[Close] button.

<figure><img src="https://media.langstack.com/documentation/media/images/code/training_manual/chapter_5/ch5closeentity.png" alt=""><figcaption></figcaption></figure>
