Related Component Entities

Entities are related if they are defined in a relationship in the application model. When used in components, related entities must be nested inside each other so that Uniface can enforce the relational integrity. Uniface understands that the primary key of the one entity is also the foreign key of the many entity, and synchronizes updates for you.

Entities that are nested in other component entities are known as inner entities. A component entity that has only the component as parent is known as an outer entity.

The multiplicity of the relationship between nested, related entities affects the default data update behavior:

  • If the inner entity represents the many side in a one-to-many relationship with the parent entity, it is called a down entity. By default, Uniface supports full create, read, update, and delete operations on both entities.
  • If the inner entity represents the one side in a one-to-many relationship with the parent entity, it is called an up entity. Deleting the parent entity is subject to delete constraints.

For example, a department can have many employees and each employee can be assigned to several projects. The following illustration shows the model that represent this (with an Employment entity to handle the many-to-many association between Employee and Project):

Data Model

Data model showing relationships between different entities.

If you want to retrieve the Department and all its Employees, you can put the Employee entity as a child of the Department entity. In this case, the child entity is a down entity, because it represents the many side in a one-to-many relationship.

Data Structure with Down Entity

Data structure in which the Employee entity is a Down entity to Department

If you want to display an Employee and all the Projects the employee has been assigned to, you can put the Project entity as a child of the Employee entity. Because the Employment entity sits between them, it also needs to be included in the data structure. In this case, the Project is an up entity, because Project represents the many side in a one-to-many relationship with Employment. You can add, update and delete Employees and Employments, but not projects.

Data Structure with Up and Down Entities

Data structure in which Project is an Up entity in relation to Employment.

When creating a data structure, you need to ensure that you correctly nest related entities to reflect the path in the model. Otherwise, you have to explicitly write code instead of letting Uniface handle the following:

  • Retrieving related occurrences from the database
  • Transporting foreign keys
  • Enforcing referential integrity constraints

Related Topics