🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Derived settable associations
This page was created by Lars.olofsson on 2021-02-18. Last edited by Wikiadmin on 2026-07-29.

You can expose an association as a calculated link for reading and define EAL that runs when a user or application sets that link; use this when changing one link must also update other attributes or links.

An association (also called a link) connects objects of one class to objects of another class. A normal derived association calculates its result with OCL and is read-only. A derived settable association adds an EAL write definition, named OclSet, so that assigning a value to the association performs controlled updates.

This is the association equivalent of a derived settable attribute. The read expression is OCL; the write expression is EAL. In EAL, the value being assigned is available in vInputParameter.

When to use a derived settable association

Use a derived settable association when the link shown to the user is calculated, but selecting a new linked object must also perform business updates.

A common case is recalculating persisted values when a link changes. For example, when a user selects a new Class2 object through Class2Selection, the write expression can update the actual link and append an entry to a log.

Do not use this pattern when a normal association can represent the required link without extra write behavior. For background on ordinary links, multiplicity, and ordering, see Documentation:Association. For a read-only calculated association, see Documentation:Derived attributes & associations.

Define the read and write behavior

Configure the association as a derived settable association and provide both of the following expressions:

  1. Define the OCL expression used when the association is read. This expression determines which object or objects the association presents.
  2. Define the EAL OclSet expression used when the association is assigned. Use vInputParameter as the incoming selected object or value.
  3. In the EAL expression, update the real persisted links and attributes that must change as a result of the assignment.
  4. Test both directions: read the association after loading an object, then assign a new value and verify the intended persisted state and any side effects.

The read expression and write expression must describe one coherent behavior. If the OCL expression presents self.Class2, the EAL expression should update self.Class2 when a new selection is assigned.

Example: selection association with logging

Assume that an object has a persisted association named Class2. You expose Class2Selection as the association used for selection in the user interface.

OCL for reading Class2Selection

When the application reads Class2Selection, return the current Class2 link:

self.Class2

EAL (OclSet) for writing Class2Selection

When the application assigns a new selection, vInputParameter is the incoming value. Set the underlying Class2 association and record the change:

self.Class2 := vInputParameter;
self.SelectionLog := self.SelectionLog + DateTime.Now.asString + ': '+ vInputParameter.Name + '\r\n'

For example, if the user changes Class2Selection to an object whose Name is Priority, the expression assigns that object to Class2 and appends a timestamped line ending in Priority to SelectionLog.

Important behavior

Topic What to account for
Read behavior The OCL expression controls what the derived association returns. In the example, Class2Selection reads from Class2.
Write behavior The EAL OclSet expression controls what happens on assignment. Assignment does not have to be limited to setting one link; it can update related persisted state, as the log update demonstrates.
Input value Use vInputParameter for the value assigned to the derived settable association. In the example it is assigned to self.Class2 and its Name is written to the log.
Side effects Keep side effects intentional and visible in the EAL expression. If an assignment changes several values, test the complete result rather than only the displayed association.

Related derivation patterns

Derived settable associations apply the same read/write pattern as derived settable attributes, except that the calculated value is a link rather than an attribute value. Read Documentation:Derived settable attributes for an attribute example in which formatted time values are read with OCL and converted back to stored values with EAL.

Use Documentation:Reverse Derivation when the entered value is a composite value that must be processed into separate stored parts. For OCL and EAL expression guidance, see Documentation:Derivation expressions and Documentation:Attribute or Data Type Conversion.

Be careful when an expression uses let together with derived associations that can change during evaluation. Documentation:Let and Derived associations explains why a let reference may be reevaluated and how to retain the object value when needed.

Example model

Load File:DerivedSettableExample.modlr in MDriven Designer to inspect the sample model for this pattern.

See also