# Relations

* An Entity can be linked to other entities. This association is termed a Relation.
* Relations can be set up between two (2) or more Entities.
* Relations use the current entity's primary keys only.
* A relation may be any of the following types:
  * One-to-One (1-to-1): One Parent Entity record can be related to One Child Entity record.
  * One-to-Many (1-to-M): One Parent Entity record can reference multiple child records in Child Entity.
* To define a relation, click on the Relations tab of the Entity to be selected as Parent Entity.

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

* Define the following fields:
  1. Relation Name: The name of the relation. It should be unique and meaningful.
  2. Type of Relation: Select relation as One-to-One or One-to-Many.
  3. Related Entity: Select Child Entity.
  4. Parent Entity Field: This field links the Parent Entity to the Child Entity. By default, the primary key of the Parent Entity is selected and cannot be edited.
  5. Related Entity Field: Specify the fields to reference the Child Entity records as this field holds the exact value of the parent entity record primary key.
  6. Cascade Delete: Checking this field defines that if a record in the parent Entity is deleted, then the related records in the child Entity will automatically be deleted. This ensures that no orphan records will remain on the deletion of the Parent record.

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.langstack.com/welcome/get-started/learn-langstack/introduction-to-entities/relations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
