Relations between classes

Most applications have more than one class and usually the classes are related, meaning that there are 'relations' between classes. A relation is always of type 'one-to-many'. This means that one object from a class can have a relation to many objects in another class, like a writer has written many books, but a specific book always belongs to one writer.

There are some definitions you should be familiar with, which were brought up in the basic concepts:

  • The class at the 1-side of the relation is called the foreign class. The involved object at the 1-side of the relation is called: the foreign object.
  • The class at the n-side of the relation is called: the connected class. The involved objects at the n-side of the relation are called: the connected objects.

Example:


Implementing the relation between classes

To implement the relation between the two classes we need an extra field in the class at the many side of the relationship (the side with the crow's foot). Usually the name of this field will be the same as the name of the other class. The content of this field always has to be one of the key fields of the class at the one side of the relationship. This field is called the 'foreign key field'. It will show the foreign class in it's data type column in the blueprint.

For example: you have a class "person" and a class "order" and you want the last to be related to the first. The class "order" is the connected class and the class "person" is the foreign class. In the class "order" you have to add a field (e.g. with the name 'person') which is the foreign key field. To define that relation you only have to set the data type of this field. In the field details, (first tab 'Properties' ) select the foreign class by clicking the "select from a list of explanations"-button. By clicking "Foreign Classes" in this screen, the foreign class can be chosen, in this case 'person'.

Label field

When there is a relationship between the foreign and connected class, a drop down list will appear in the foreign key field in the application. This drop down list contains the values of the key field from the foreign class. It is possible that these are not the values you want to see, since the standard behavior of the engine is to put the key field values in the drop down list. If you want to show other vaues in your application you need to set a "Label field" value in the foreign class. This property is to be found in the "Properties" tab of the foreign class, see image below. 
Because the prefix is a blank it's not visible on the screen

  
 
As soon as you have added a label field, the values of that field will be shown as a drop down list in the connected class. When you have defined more than one field, all of them are shown.