The remove operator lets you unlink a known object from a collection or association in an OCL executable action, for developers who need to change an association rather than produce a filtered result.
Syntax
Collection.remove(itemToRemove)
| Part | Meaning |
|---|---|
Collection
|
The collection or association from which you want to remove an object. For example, vCurrent_Customer.Orders.
|
itemToRemove
|
The specific object to unlink from that collection. For example, an Order held in the variable x.
|
What remove changes
remove is an Executable Action Language (EAL) command. It changes the actual association or collection on which you call it.
For example, when you evaluate:
vCurrent_Customer.Orders.remove(x)
MDriven removes the link between vCurrent_Customer and the order represented by x. The Order object is not deleted; it is no longer included in that customer's Orders association.
This differs from excluding, which returns a collection with an item left out but does not modify the underlying association.
Remove selected orders from a customer
Use remove when a user has selected existing objects and you want to unlink each selected object from the current object's association.
Assume that:
vCurrent_Customeris the current customer.vSelected_Orderscontains the orders selected in the user interface.vCurrent_Customer.Ordersis the association to update.
Evaluate the following action:
vSelected_Orders->collect(x | vCurrent_Customer.Orders.remove(x))
The expression processes every selected order. For each order, represented by x, it calls remove on the current customer's Orders collection.
| State | Result |
|---|---|
| Before the action | The customer is linked to five orders. |
| User selection | Two of those orders are present in vSelected_Orders.
|
| After the action | The customer is linked to three orders. |
| Order objects | The two order objects still exist; only their links to this customer have been removed. |
Choose the item by object, not position
Use remove when you have the object to unlink, such as a selected order stored in x. If you need to remove an item according to its numerical position in a collection, use removeAt instead. removeAt uses zero-based indexes, so index 0 identifies the first item.
