Custom Types can implement four pre-defined Callback Methods that are executed when an object of that type is subject to external changes.
error() method, which will fail the transaction and cause a
422 Unprocessable Entity error to be sent to the user.
Called when a new instance of this Custom Type is created in the database.
onCreate script sets the
timestamp property of a newly created entity to the current time and date and triggers Geocoding. This example illustrates the syntax of the template expression used in callbacks.
( set(this, 'timestamp', now), set(this, geocode(this.street, this.city, this.country)) )
The next example illustrates the use of the
error() method to prevent the creation of invalid entities in the database.
( if(empty(this.name), error('User', 'name', 'must_not_be_empty'), null, ) )
Called when an instance of this Custom Type is modified (this does not include creation). Just like
onSave can prevent the modification of an object with the
Called when an instance of this Custom Type is deleted. The
error() function can be used on
onDelete as well.
Called when a File is downloaded.
You can of course declare more than one method of each type, suffixing the individual methods with a number (e.g.
onCreate01, onCreate02, …). This allows you to specify a series of functions that will be executed when a new entity is created.