You use the Save EAL operator in a ViewModel action to commit the changes made in the current ViewModel to persistent storage.
What Save does
Save persists the changes that are currently pending in the ViewModel. This includes changed attribute values and objects marked for removal with delete.
For example, if a user edits a customer's name in a ViewModel and then runs an action containing Save, the changed name is committed to persistent storage. If the action has marked an order with delete, that order is permanently removed when the save operation is performed.
Use Save in a ViewModel action
- In MDriven Designer, open the ViewModel that contains the data the user can change.
- Add or select the action that should commit those changes, such as a Save button action.
- Add the Save operator to the action's EAL expression.
- Run the action after the user has completed the changes.
Save operates on the current ViewModel context. See SelfVM for the ViewModel reference used by EAL expressions.
Save lifecycle behavior
When an object is saved, its OnUpdate action runs immediately before the object is saved to the database. Put logic that must run for each save operation, such as updating a change timestamp, in OnUpdate rather than repeating it in every save action.
Do not create new objects inside OnUpdate. Objects created there can remain unsaved.
Save is not file export
Save commits model changes to persistent storage. It does not create a file for the user or server. To write string or blob data to a file on the machine executing the logic, use SaveToFile.
Example
A ViewModel displays a Customer and lets the user edit Name.
- The user changes
NamefromNorthwindtoNorthwind Traders. - The user invokes the ViewModel action that contains Save.
- The pending Customer change is committed to persistent storage.
- Before the Customer is saved, its OnUpdate action runs, if one is defined.
