One-to-one relationships

<< Click to Display Table of Contents >>

Navigation:  Examples  > Patterns >

One-to-one relationships

Previous pageReturn to chapter overviewNext page

Pairing is a common phenomenon:

A company has one board of directors, a board of directors governs one company.

Every spouse has one spouse.

Every rat heart belongs to one rat, every rat has one rat heart.

 

In this section we explain how to use attributes to establish a pair relationship between two entities. The goal of creating such a relationship in Ventity is so that each member of the pair can use information from the other member in equations. If each company entity uses input from its board of directors entity, we must ensure that Ventity knows precisely which board of directors entity (out of, potentially, thousands) governs any particular company.  

 

In our example, the two entities will be of different types, but the mechanics change little to connect two entities of the same type.

 

In the pattern model "one to one", available in the Sample Projects directory, we use the example of a rat heart entity and a rat entity. This might be a valid choice if you are studying the dynamics of the rat heart, and want to use the rat entity to represent the rest of the animal.

 

onetoone.1

 

There are three key steps to creating one-to-one relationships:

1.Each entity must have an attribute that names the relationship. In this case, the rat entity has a "heart" attribute and the heart entity has a "rat" attribute.

2.The attributes must have their "Refers To" field set to the other entity's type. As shown below, the rat's "heart" attribute refers to an entity of type heart, and vice versa:

 

onetoone.2

 

This is important because it will automatically establish references between the two entities, visible in the reference tab of each inspector:

 

onetoone.3

 

These references permit each rat entity equations to use heart variables such as heart rate of its own heart, and heart entity equations to use rat variables, such as diet.

 

3.The last step to establish the connection is to set the pairs during initialization, matching rat ID's with heart ID's. In this example we've initialized two rat entities, Sam and Edith,

 

onetoone.4a

 

and a heart entity for each rat:

 

onetoone.4b