---
title: "Entities Relationships: Linking Entities"
canonical: "https://onesaitplatform.refined.site/space/DOCT/2220833504/Entities%20Relationships%3A%20Linking%20Entities"
format: markdown
---
> ℹ️ From version 3.1.0 in the Control Panel, Ontologies have been renamed as Entities. This does not alter any functionality, simply the nomenclature has been changed for a better understanding of the concept.

As of now, you can make relationships between ontologies through their attributes/properties. This tutorial will guide you on how to achieve this, also explaining the features this functionality involves.

## Creating the links/references

Ontology relationships are defined at JSON Schema level, so there are two ways of making them:

### **From the creation wizard**

Head to the Ontology creation wizard in the menu **Development→Manage Ontologies→New→Creation Step by Step**.

In this case, we are going to create an Ontology representing sales of different Firms across the globe, so this ontology will have the following properties:

![image](media://bfd0729a-cf01-482d-8c8b-a7804f8ec70d)

The country property will be expressed as stated in ISO 3166-1 alpha-3, as this is the standard that we are using within the platform for several applications. Because of this, we already have an ontology modeling this ISO 3166-1, so let's <u>link both properties Sales.country</u>, with <u><span style="color: #003366">ISO3166_1.alpha3</span></u>.

Click on 'Linked Data', below the properties table, and this will pop up a window to add/delete relationships between ontologies and their properties.

To make the one we are looking for, we are going to select the following values:

![image](media://4fbb0df3-f08f-491b-a3a5-b7897eb2e610)

Source property is country, and target property alpha3 its from ISO3166_1.

**NOTE: **Only properties of the same type (string, number, integer, object...) can be linked.

<span style="color: #003366">**NOTE:  **</span><span style="color: #003366">Validation is optional. If you set validate to True, this means that any data related with this ontology (Sales) ingested by the platform will be involved in a validation process, where the platform will only save the data if the code in 'country' exists in ISO3166_1.alpha_3 database. The default is False.</span>

Once all of this is selected, click on **Add reference**.

![image](media://2217e7b6-4a2b-4dbb-9efc-3bbb3bbd8511)

Now that the reference is made, you can close the window and click on **Update schema**.

![image](media://306c1c77-ee94-44f5-920f-2a663dc47f4a)

As you can see in the generated Schema, there is an extra node named **_references.** This node will carry the information needed by the platform to identify and operate this relationship of properties.

You can now finish the creation process by clicking on **Create**.

### **By editing a JSON Schema**

You can also make references programmatically by editing the JSON Schema.

To do this, you have to create the node '_references' from the root node. Then define 'self','target' and 'validate'.

'self' must be the absolute path to the attribute of source Ontology. Ex: Sales.country path is datos.properties.country.

'target' has the following structure: 

[URL to Ontology Schema](https://mind.indra.es/pages/createpage.action?spaceKey=WKOP&title=URL+to+Ontology+Schema&linkCreation=true&fromPageId=280693724)#[Path to property](https://mind.indra.es/pages/createpage.action?spaceKey=WKOP&title=Path+to+property&linkCreation=true&fromPageId=280693724)  
URL to Ontology Schema: this is always 'ontologies/schema/[Ontology](https://mind.indra.es/pages/createpage.action?spaceKey=WKOP&title=Ontology&linkCreation=true&fromPageId=280693724)  
#: Ontology to property separator.  
Path to property: as in 'self', the absolute path to property.

'validate' set to true or false, recommended is false.

**NOTE: **This method may be useful to link properties embedded in objects, for example, linking a property (dni, String), with a property (dni, String) inside another property (person, object) : o1.dni → o2.person.dni

## Graphical representation of the linked ontologies

Now that we have made the relationship, we can go to **/controlpanel/main** to see it.

![image](media://8a3a443c-addd-48cf-b93e-5b3a890910bb)

  
As you can see in the graph, both ontologies, Sales and ISO3166_1 are linked. If you click on the 'Parent' ontology (Sales) you can see the relationship in the description. 

![image](media://32e94ab7-f2a7-4dc7-b2d0-997a8ed6dc52)

This description of the relationship is readable. Attributes are written straightforward, avoiding the use of property paths (this is just for defining them in the Schema).

## Using QueryTool with autogenerated INNER JOINS

If you go to the QueryTool service under **Tools→Query Tool,** and you select an Ontology which has defined any relationship with another, a new option is available in the service: the JOIN panel. This panel is used to mount automatically SQL INNER JOINS with linked ontologies.

![image](media://1d6372ca-cea7-451d-bf38-fc2faf7c68d2)

If you click on **+,** a new window will pop to select the attribute you want to query in the JOIN sentence.

![image](media://87efc34b-b78b-47c9-9901-755cb05f9f02)

Once selected source property, you may choose target in **Ontology→property** available for the JOIN.

Click **OK** and the query will be created, then you can execute it to see results (assuming there is data already in the database):

![image](media://b2a2675a-cad1-40f6-91be-3274db130ef1)

As you can see in the results, both properties, country and alpha3 have the same values (ESP).

**NOTE: **This example was performed with two ontologies with MongoDB as datasource, but the same will work for ontologies stores in ElasticSearch.

**NOTE: **You can also link ontologies with different datasources, everything will work fine apart from JOINs, but <u>it is not possible to make JOINs between ontologies with different datasources as this is not yet implemented in the platform.</u>

## Elasticsearch example:

![image](media://b337c8b9-67cf-4ef6-a30e-f958c6203f34)