4D v16

Using Relations

Home

 
4D v16
Using Relations

Using Relations    


 

 

Relations established between 4D tables are used tranparently in the context of a 4D Mobile link. However, the way these relations are represented differs in Wakanda at the model level. In the model editor, relations are linked with specific attributes, called relational attributes. These attributes can be used to display the linked data directly or to perform queries. For more information about this, refer to the "Attributes" section in the Wakanda documentation. 

For each relation established on the 4D side, two relational attributes are added in the model representation on the Wakanda side:

  • an n->1 attribute in the source table (class) of the relation
  • a 1->n attribute in the destination table (class) of the relation.

Both these attributes are given the name of the relation as it was defined respectively for the many-to-one and one-to-many relation in the Inspector on the 4D side.

For example, let’s imagine that in the context of a "Employee/Company" structure, you create a relation from the [Employee] table to the [Company] table. You can characterize this relation by means of the name you give it: for example, you could name the many-to-one relation "worksFor" and the one-to-many relation could be "employs":

On the Wakanda side, through a link via the connector, these relations are automatically materialized by two additional relational attributes, that you can see in the Model editor:

You can give these relations (and thus their corresponding relational attributes) any name you want, based on the logic of your application. 

The advantage of this is that it is very simple to use these attributes on the Wakanda side to work with the related data. More particularly, you can create widgets associated with datasources that are based on relational attributes. These widgets are then managed and updated automatically according to user actions. 

For instance, it is very simple to create a page containing one grid with the list of companies, and another listing the employees of the company selected. To do this, you just associate the "Company" datastore class with one grid, and the "employs" relational attribute with the other:

The corresponding datasources are automatically created, and during execution, both grids are synchronized automatically:

 
 

 
PROPERTIES 

Product: 4D
Theme: Using Relations

 
HISTORY 

 
ARTICLE USAGE

4D Mobile ( 4D v16)