# Relationship

## Overview

A **Relationship** in ReOrc defines how different Cubes are connected, enabling seamless data integration and enhancing analytical capabilities. Establishing relationships between Cubes ensures consistency, improves query performance, and facilitates the creation of meaningful Views.

## Concept of Relationship

A **Relationship** represents the logical connection between two or more Cubes based on common keys. These relationships allow data from multiple Cubes to be combined, enabling cross-referencing and enriched analysis.

#### Types of Relationships:

* **One-to-One (1-1)**: Each record in one Cube corresponds to exactly one record in another Cube.
* **One-to-Many (1-n) or Many to One(n-1)**: A single record in one Cube is associated with multiple records in another Cube.

## Why Setup a Relationship?

#### **For View Creation**

* Relationships allow Views to aggregate and display data from multiple Cubes seamlessly.
* Enables pre-joined datasets that improve performance in BI tools.

#### **For Data Consistency and Integrity**

* Ensures correct data linkage across different datasets.
* Reduces redundancy and improves maintainability.

#### **For Enhanced Query Performance**

* Predefined relationships optimize query execution by reducing the need for complex joins at runtime.
* Improves efficiency by leveraging indexed relationships for faster data retrieval.

## Define Relationships

To define the relationship between cube, follow these steps:

{% hint style="info" %}
Ensure the cube's primary key has been set before proceed to create the custom dimension. Refer [Cube](/semantic-modeling/cube.md#create-cube)
{% endhint %}

1. Click on the **Edit Relationship** button, the relationship modal will be shown

<figure><img src="/files/AwyVRarMzNruibwdvurD" alt=""><figcaption></figcaption></figure>

2. Click on **Add Relationship** to start add a new row of the relationship between cube.
3. Select the Relationship Type, From and To fields in the list and click on **Add** button.

<figure><img src="/files/fWPC8wRkwDdGtyoUwO4o" alt=""><figcaption></figcaption></figure>

4. Once the relationships have been defined, click on the **Save** button to save all the relationships created.

<figure><img src="/files/cFLRKDqrrUbNcCpAympN" alt=""><figcaption></figcaption></figure>


---

# 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.reorc.com/semantic-modeling/cube/relationship.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.
