The DiscardChanges OCL operator lets you cancel pending changes for a collection of objects, making it useful when you want a user to abandon edits in a ViewModel.
What DiscardChanges does
DiscardChanges iterates over the objects in the collection that precedes it and reverts their pending state to the last known state in persistent storage (the database).
It discards changes that have not been saved, including pending edits, additions, and deletions for the objects in the collection. It does not save anything to persistent storage.
Use DiscardChanges for a Cancel action, or whenever you need to abandon the unsaved changes currently tracked by a ViewModel.
Syntax
collection->DiscardChanges
| Part | Meaning |
|---|---|
collection
|
The collection of objects whose pending changes you want to discard. |
->DiscardChanges
|
Reverts the objects in that collection to their last known persistent state. |
Discard all pending changes in a ViewModel
selfVM.DirtyList returns all changed objects that would be saved if selfVM.Save were called. To cancel all pending changes in the current ViewModel, use:
selfVM.DirtyList->DiscardChanges
For example, place this expression in the action that handles a Cancel button. When the action runs, the ViewModel's currently changed objects are reverted instead of being committed.
Choose discard or save
| If you want to... | Use |
|---|---|
| Keep the pending changes by committing them to persistent storage | Save |
| Abandon pending changes for a collection of objects | collection->DiscardChanges
|
| Check whether an object has changed since its last save | IsDirty |
Important behavior
- Call
DiscardChangeson the collection whose pending changes you intend to cancel. The collection determines which objects are reverted. - Use
selfVM.DirtyList->DiscardChangeswhen the intended scope is every changed object in the current ViewModel. - Changes that have already been committed with Save are not pending ViewModel changes and are not undone by this operator.
