🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
OCLOperators Qualify GenericAt0
This page was created by Vale.buyondo on 2026-03-04. Last edited by Wikiadmin on 2026-07-29.

You can use Qualify_GenericAt0 to retrieve the first object in a root-level association when MDriven falls back from bracket qualifier syntax; it is intended for users working with OCL expressions against SysSingleton / ECOModelRoot.

Purpose

Qualify_GenericAt0() is an internal fallback operator. MDriven uses it when bracket qualifier syntax ([ ]) is applied to an association that has no explicit Qualify implementation.

The operator retrieves the object at position 0 from a named association role on the model root. Position 0 is the first object in the role collection.

For example, if SysSingleton has an association role named ApiSearchResults, the first linked article can be addressed with the preferred expression:

SysSingleton.allInstances->first().ApiSearchResults[0]

Requirements and limits

Requirement What it means
Root context only Call the operator only on the root class, SysSingleton / ECOModelRoot. Calling it on another class produces: Second param must be a valid multilink name as string literal for class of root.
Association role name Supply the association role name, not an attribute name. The name must match the role shown in the Roles panel in the OCL Editor when SysSingleton is selected.
First position The operator is for position 0. In bracket syntax, indexes are zero-based: [0] is the first object.
Runtime link required The target object must be linked through the root association at runtime. An independently existing instance of the target class is not returned.

Find the correct association role

  1. In the OCL Editor, select SysSingleton.
  2. Open the Roles panel.
  3. Find the multi-link association that contains the objects you need.
  4. Copy the role name exactly as displayed. For example, use ApiSearchResults, not the name of an attribute on an article.
  5. Ensure that your application has linked the target object to that root role before the expression is evaluated.

Example

Assume an object has been linked to the ApiSearchResults role on SysSingleton. To retrieve the first linked object, use bracket syntax:

SysSingleton.allInstances->first().ApiSearchResults[0]

The expression returns the object at index 0 in ApiSearchResults. If no object has been linked to that role, it returns null.

Preferred expressions

Do not call the internal fallback operator directly when a normal OCL expression expresses the intent. Use one of the following alternatives instead.

Use case Preferred OCL Result
Retrieve the first item by bracket syntax SysSingleton.allInstances->first().ApiSearchResults[0] Returns the item at zero-based index 0.
Retrieve the first item with a collection operation SysSingleton.allInstances->first().ApiSearchResults->first() Returns the first item in the ApiSearchResults collection.

Empty collections and missing links

The result is null when the root role collection is empty or when no target object has been linked to the role at runtime. This remains true even when instances of the target class exist elsewhere in the model.

For example, creating an Article does not make it available through ApiSearchResults. The article must also be linked to SysSingleton.ApiSearchResults.

See also