You can use orderDescending in an OCL expression to sort a collection from the highest value to the lowest value; it is for developers defining ordered results in MDriven Designer.
Syntax
collection->orderDescending(iterator | sortExpression)| Part | Meaning |
|---|---|
collection
|
The collection to sort. |
iterator
|
A temporary name for each object in the collection. |
sortExpression
|
The attribute, or supported path of attributes, used as the sort key. |
The result is the same collection ordered in descending order. For text values, this means reverse ascending order; for numeric or date values, the largest or latest value appears first.
Sort cars by name
Given a Car class with a Name attribute, sort a collection of cars by name from Z to A:
Car.allinstances->orderDescending(car | car.Name)For cars named Alpha, Roadster, and Zephyr, the result order is Zephyr, Roadster, Alpha.
Sort by a number or date
Use the value that defines the order as the sort expression. For example, to show cars with the highest mileage first:
Car.allinstances->orderDescending(car | car.Mileage)To show the most recently registered cars first:
Car.allinstances->orderDescending(car | car.RegistrationDate)The sort expression can follow single links to reach an attribute on a related object. For example, if each car has one Owner and an owner has a Name attribute:
Car.allinstances->orderDescending(car | car.Owner.Name)Be aware that ordering through related information uses a join. It is not an outer join: a car without the required related data is excluded from the result set.
Choose the correct ordering operator
Use orderDescending when the highest, latest, or reverse-alphabetical values must appear first. Use orderBy when you want ascending order instead.
