Inverse References Involving Runtime Dynamic Properties

JADE inverse references are used to define relationships between classes. For details about using the JADE development environment to define a relationship, see "Defining an Inverse Reference Property", in Chapter 4 of the JADE Development Environment User’s Guide.

A relationship can also be defined using runtime dynamic properties as the inverse references. For example, a one‑to‑many relationship (one customer has many appointments) could be established between the Customer class and Appointment class, as shown in the following diagram.

The runtime dynamic properties implementing the relationship are allAppointments, which is an exclusive collection property in a dynamic property cluster associated with the Customer class, and myCustomer, which is a property in a dynamic property cluster associated with the Appointment class.

The Property class method addDynamicInverse, which has the following signature, adds an inverse between the receiving dynamic property and the dynamic property specified in the property parameter.

addDynamicInverse(property: Property;
                  mode: Character;
                  kind: Character): Property subschemaFinal, updating, abstract;

This method returns a reference to the receiving dynamic property with the inverse added. Note that when the first inverse is added, this will be different from the receiver.

The property parameter must identify a compatible dynamic property; for example, if the type of the property is a Collection class, the schema type of the receiver must be compatible with the membership of the collection.

If instances of the class of either dynamic property exist and the dynamic properties have non-null values, the inverse relationship is not validated or populated when the inverse definition is added.

The values for the mode parameter are defined by the following ExplicitInverseRef class constants.

The values for the kind parameter are defined by the following ExplicitInverseRef class constants.

The Property class removeDynamicInverse method, which has the following signature, removes an inverse reference between the dynamic property specified in the property parameter and the receiver.

removeDynamicInverse(property: Property): Property subschemaFinal, updating, 
                                        abstract;

This method returns a reference to the receiving dynamic property with the inverse removed. Note that when the last inverse is removed, this will be different from the receiver.

In the following example, the runtime dynamic properties for each class are created, and then an inverse relationship is established between them.

vars
    custCluster, appCluster     : JadeDynamicPropertyCluster;
    myCustomer, allAppointments : Property;
begin
    beginTransaction;
    // Add 'allAppointments'
    custCluster := Customer.findDynamicPropertyCluster("CustomerCluster");
    allAppoinments := custCluster.addExclusiveDynamicProperty("allAppointments",
                                                               AppointmentDict);
    // Add 'myCustomer'
    appCluster := Appointment.findDynamicPropertyCluster("AppointmentCluster");
    myCustomer := appCluster.addDynamicProperty("myCustomer", Customer, 0, 0.Byte);
    // Define inverse relationship
    myCustomer := myCustomer.addDynamicInverse(allAppointments,
                                              ExplicitInverseRef.UpdateMode_Manual,
                                              ExplicitInverseRef.Kind_Peer);
    commitTransaction;
end;

Code that sets up inverse references must be executed before code that uses the inverses.

You cannot define inverses between runtime dynamic properties through the Class Browser.