You can use setToNull in OCL Executable Action Language (EAL) to clear a nullable attribute or a single-link association with multiplicity 0..1.
What setToNull does
setToNull explicitly assigns a database NULL value to the target property. Use it when an existing value must be removed rather than replaced.
For example, clearing an order date removes the date value from that order:
Order.allinstances->first.OrderDate.setToNull
After this expression runs, OrderDate is empty for the selected Order.
Syntax
[Object].[NullableProperty].setToNull
The target must be one of the following:
| Target | Result | Example |
|---|---|---|
| Nullable attribute | Clears the attribute value. | Order.OrderDate.setToNull
|
Single-link association with multiplicity 0..1
|
Clears the association so that it no longer points to an object. | Order.Customer.setToNull
|
Clear a nullable attribute
Use setToNull directly on the nullable attribute.
Order.allinstances->first.OrderDate.setToNull
In this example, Order.allinstances->first identifies an Order, and setToNull clears its nullable OrderDate attribute.
Clear a 0..1 association
You can also clear a single-link association when the association allows no linked object. For example, if an Order has an optional Customer link, the following removes that link:
Order.allinstances->first.Customer.setToNull
Use this form only for a single-link association with multiplicity 0..1. It does not apply to an association that requires a linked object.
Alternative: assign nullValue
You can produce the same result with the assignment operator := and the type's nullValue:
Order.allinstances->first.OrderDate := DateTime.nullValue
This assigns the null value for the attribute type to OrderDate. Use setToNull when you want the intent to clear a value to be explicit; use := <Type>.nullValue when an assignment expression is more suitable in the surrounding EAL.
