Define a relationship

Define a relationship

Relationships define how entities relate to one another. All entities must have a containment relationship defined, which specifies the overall structure of the rulebase. In addition, reference relationships can be defined between entities if appropriate for your data model. You need to have already defined your entities before you can add reference relationships.

By specifying a relationship you are specifying whether an instance of an entity is related to one or more of the instances of another (or even the same) entity group.

For example, if you have:

Then there is a single relationship, but there are three relationship instances, because each person has a list of the cars that belong to them.

That is, Tom has a VW and Mazda, Dick has a Ford, and Harry has a Holden and Ford.

What do you want to do?

Understand the different types of relationships

Create a relationship in a properties file

Understand the different types of relationships

One-to-One

A one-to-one relationship is where one entity instance interacts only with one other entity instance.

 

Entity 1: the nut

Entity 2: the bolt

Relationship from the nut to the bolt: the nut's bolt

One-to-Many

A one-to-many relationship is where one entity instance interacts with many other entity instances. This is the traditional hierarchical model relationship.

 

Entity 1: the owner

Entity 2: the pet

Relationship from the owner to the pet: the owner's pets

Many-to-Many

A many-to-many relationship is where multiple instances can interact with many other entity instances. In the example below, the Pets "Bella" and "Lochie" share the Owners "Ping" and "Euan", whilst Chip has only one owner Euan.

 

Entity 1: the pet

Entity 2: the owner

Relationship from the pet to the owner: the pet's owners

TIP: To see a simple example of a complete rulebase with a many-to-many relationship, open and run the Parents And Children example rulebase project provided in the Examples folder in the Oracle Policy Modeling installation folder.

Many-to-One

A many-to-one relationship is where many entity instance belong to only one entity instance. This is the reverse of a one-to-many relationship.

 

Entity 1: the pet

Entity 2: the owner

Relationship from the pet to the owner: the pet's owner

Reverse Relationships

Reverse relationships occur where an entity has a relationship to another entity, and that entity has a relationship back again. For example, a parent has a child and a child has a parent.

However, not all relationships have a logic reverse and not all relationships require capturing the reverse relationship. For example, it might be useful to collect that an applicant has applied for multiple benefits but there is no need to identify all of the applicants for a particular benefit.

In determining whether or not to capture a reverse relationship, consider whether both directions of the relationship will be useful in your rules. If in doubt, create the reverse relationship - it won't be activated unless you have rules which refer to it.

Primary Direction

The primary direction of a relationship applies to relationships that also have reverse relationships. The primary direction determines the primary relationship for the pairing of relationship to reverse relationship. This is important for inferred relationships: an inferred relationship may only be proved by a rule in its primary direction.

Self-Referential Relationships

Sometimes it is necessary to relate one entity instance to another entity instance in the same entity. For example, a child in a family may have a special relationship with another child in the family, such as being twins or sharing a room.

This type of a relationship is treated the same as other relationship types, except that both the source and the target of the relationship are the same entity.

Containment Relationships

All entities must have a containment relationship defined. The collection of containment relationships that link entities in the rulebase together allows us to see the logical structure of the data model. For example, a rulebase may have two entities 'the guardian' and 'the child', with two containment relationships defined: a one-to-many relationship "the guardians" from the global entity to the guardian entity, and a one-to-many relationship "the guardian's children" from the guardian entity to the child entity. The containment relationship for an entity must be either many-to-one or one-to-one, ie each entity instance must be contained by a single parent entity instance. Additional relationships (reference relationships, see below) between entities can be defined as needed for your rulebase data model. See Understand containment relationships and entity completion for more information.

Reference Relationships

Reference relationships define meaningful connections between entities that exist in addition to the entities' containment relationships. For example, an entity 'the person' may have a containment relationship from the global entity called "the people", and an additional reference relationship to capture groups of people who live together called "the person's housemate", which is a self-referential relationship between instances of the person entity.

Inferred Relationships

An inferred relationship is a many-to-many relationship that has its membership concluded by rules in the rulebase.

Create a relationship in a properties file

Relationships are defined in a properties file for the project, rather than in individual Word and Excel documents. This eliminates the need to re-define the same relationships in each rule file.

Create a containment relationship

Containment relationships are automatically created when the associated entities are first created in the rulebase. However, you should provide more meaningful relationship text by editing the relationship before using the relationship in your rules.

To edit a containment relationship:

  1. In Oracle Policy Modeling, double click your properties file to open it. Select the entity that you want to edit the containment relationship for. The containment relationships already created for the entity will be shown on the Relationships tab.



  2. Double click on the relationship to open the Relationship Editor dialog box.



  3. Change the Text for the relationship.



    Click OK. You can now use your new relationship text in rules.

Create a reference relationship

To create a reference relationship between two entities in a properties file:

  1. In Oracle Policy Modeling, double click your properties file to open it. Select the entity that you want to create a relationship for.



  2. In the Relationships window, right-click and select New Relationship...



  3. In the Relationship Editor dialog box, select the browse button next to the Target field to select the target entity.



  4. In the Entity Selector dialog box select the target entity.



    Then click OK.
  5. In the Relationship Editor dialog select the type of relationship from the drop-down menu.



  6. Enter the textual form of the relationship name in the Text field. Relationships should be given a meaningful name, usually using the definite article 'the' (for example, 'the children', 'the child's school' etc). For more information, see Choose a name for a relationship.



  7. Enter the textual form of the reverse relationship in the Reverse Text field. If a reverse relationship is not specified then by default it is not possible to traverse the relationship backwards.



  8. Click OK. Repeat this process for any additional relationships you want to add. The relationships that you have added will now be displayed on the Relationships tab.

 

NOTE: For any relationships that you want to export in a module, you need to specify public names on both ends (ie in the Public Name and Reverse fields in the Relationship Editor).

Flip the direction of a relationship

The primary direction of a relationship is important - you cannot infer a relationship or collect one on a screen from the non-primary direction. The primary direction will be assumed to be the direction in which the relationship was first created. If you want to set it in the reverse direction, you will need to flip it. To do this:

  1. In Oracle Policy Modeling, double click your properties file to open it. Select the entity that the relationship relates to.
  2. In the Relationships window, double click the relationship to open the Relationship Editor.



  3. Click the Flip Primary Direction button. You will notice that:
    1. the Source and Target entities have swapped, and
    2. the primary Public Name has swapped with the Reverse public name, and
    3. the Relationship type has been reversed, and
    4. the primary Text and Reverse Text have swapped.



  4. Click OK.