Skip to content

Relationship

VinceZK edited this page Apr 9, 2020 · 6 revisions

In JOR, relationship is used to connect entities to form a graph. You can traverse from one entity to other entities through relationships. A relationship can have attributes, therefore, it is also a relation.

Relationship is not defined on entities, but on roles. When a role is assigned to an entity, the relationships on the role are then transferred to the entity. In other words, whether two entity instances can be connected using a relationship is determined by the roles assigned to the entities.

Create Relationship

In the modeling tool, go to the 'Relationship' tab. The left list shows the 10 latest entities in the system. You can run a fuzzy search which filters in names and descriptions. Click the '+' button on the top right, you can create a new relationship.

You must give a unique name started with 'rs_', and optionally, some description.

Time Dependent

In reality, relationships are not permanent. Every relationship will come to an end. For example, a marriage can be ended either by divorce, or husband or wife died. In JOR, you can define a relationship as time dependent. A time-dependent relationship has 2 special attributes: 'VALID_FROM' and 'VALID_TO'. Only between the time period, the relationship is valid.

If 'Time Dependent' is checked, you need to provide a default period of validity in seconds. By default, 31536000 is given which stands for a 1-year validity period. You will also find the 2 attributes 'VALID_FROM' and 'VALID_TO' are automatically added to the attribute table. They are in gray and are not allowed to be deleted as normal attributes. During the creation of a relationship instance, 'VALID_FROM' is by default set to the current time, while 'VALID_TO' is calculated by adding the default validity period to current time. You can of course adjust the value of 'VALID_FROM' and 'VALID_TO' manually.

Attribute

You add relationship attributes just like adding attributes in Relation. However, there are 2 differences. First, primary key(PK) and auto increment(AI) are not supported as each relationship instance has an internal instance GUID as its primary key. Second, there are fixed attributes which are generated automatically.

When a role is added into the relationship, 2 fixed attributes are added. They are '<role_name>_INSTANCE_GUID' and '<role_name>_ENTITY_ID'. They cannot be deleted as normal attributes, but only be deleted when the corresponding role are removed from the relationship.

Besides, when the relationship is checked as time-dependent, 'VALID_FROM' and 'VALID_TO' are added automatically.

Involved Roles

At least, 2 roles should be assigned to a relationship, as a relationship must at least involves 2 entities. Like husband and wife in the marriage relationship. There are also cases that more than 2 entities involved in a relationship. For example, a family relationship may contains father, mather, and the children.

Roles are added to a relationship with cardinality. There are 2 cardinality options: '[1..1]' and '[1..n]'. With '[1..1]', it means an entity with this role can only be involved in one such kind of relationship in a given time. Like a man or a woman can only be involved in one marriage relationship in a given time. With '[1..n]', it means an entity with this role can be involved in multiple such kind of relationship instances. For example, a man can have a lot of friends at the same time.

The 'Singleton' supplements the cardinality '[1..n]' in such case that the combination of the entities should only appear once in a relationship. For example, the friend relationship is singleton. It is weird to define 2 such kind of relationship instances with the same group of people. However, the debtor and creditor relationship is not singleton. A debtor can borrow money from a creditor in many times. Then there are multiple debt relationship instances between the same debtor and creditor.

Change Relationship

You can add or remove relationship attributes just like in Relation. Besides, there are many cases in changing a relationship that cause inconsistencies. All these inconsistencies can only be manually corrected. Here lists some:

  1. Change a time-dependent relationship to non-time-dependent, or vice versa.
  2. Change a non-singleton relationship to singleton.
  3. Add or remove roles.
  4. Change the cardinality from '[1..n]' to '[1..1]'.