Relation Management in NDO
NDO takes care that child objects in relations are loaded automatically if the fields representing the relations are accessed. Objects included in a relation are just there from the developer's view.
Relations between persistent and deleted objects are cleared by NDO.
NDO manages bidirectional relations automatically. Let’s assume we have two classes, Conference and Participant. Each participant owns a list of conferences he already attended. If a new participant is added to the participant list of a certain conference, NDO adds the conference automatically to the conference list of the participant.
This behavior can be avoided with role names (Relation Names) if it is not desirable (see below).
In larger applications it can easily happen that there are several relations to the same target class with different meaning. The class Person can be connected with the class Car in the role Owner and Seller. To distinguish these roles the relations receive names:
NDO will create two foreign keys in the table Car in this situation. Each of them is assigned to one of the two roles. The default role name is an empty string, thus two reciprocal relations without Relation Names are interpreted as bidirectional relations by NDO automatically.
It is often desirable to hold elements of different classes in a list that have a base class in common. NDO supports this with abstract base classes. You can find more about that in the chapter about polymorphic inheritance below.
A class can also have a relation to itself. Here is an example:
Employee director; // 1:1
IList office_staff; // 1:n
The example shows a bidirectional relation; both sides are using the same foreign key.