Entity Persistence Settings
Learn about persistence settings of an Entity.
Persistent vs Virtual Entities
A Persistent Entity is an entity which is stored in the database. All fields of an entity with the type Persistent are created as columns in the entity's database table.
A Virtual Entity (non-persistent) is an entity that is never stored in the database.
Every new entity is by default persistent. You can see control of this with the Persistence > Is Persistent property. If you want to make the entity virtual/non-persistent then uncheck the Persistence > Is Persistent property of the entity.
Specifying the Table to use - the Persist In property
For persistent entities that use other persistent entities as behavior patterns, there is a choice to use the inherited entity's table as the persisting table. So the base entity may be used to store derived entities as well. You can control this by selecting the persisting entity in the Persistence > Persist In property for an entity. If left blank, persistent entities are stored in their separate tables.
Specifying the Database to use - the Default Data Source property
The database in which an entity is to be stored can be selected in the entity's Persistence > Default Data Source property. If left blank, the database may be decided by the entity APIs responsible for the CRUD operations.
If you use any of the XLib.* patterns such as Persistent Object, then the APIs that are inherited are configured to use the Core DataBase component from the XLib.Core library. If you open any of the CRUD APIs in the designer and look at the Properties > Data Source property of the DataBase Operation in the API, you can see Core DB has been selected there.
Post Save/Delete logic - The post Persistence API Name property
A post-persistence API is a JavaScript action that gets called after every INSERT/UPDATE/DELETE operation on an Entity.
You may specify the post-persistence API for an Entity by providing the action's resource ID in the Persistence > Post Persistence API Name property.
The post-persistence JavaScript action receives the following in the input variable: { data: <The Data Record JSON>, action: "insert/update/delete" }
Example of a post-persistence API JavaScript action:
if (input.action == "insert") {
varAPI = session.getApi("addnewmomentuser");
API.parameters = API.getEntity().createEntityObject(session);
API.parameters.username = input.data.username;
API.parameters.email = input.data.email;
API.parameters.password = input.data.password;
API.execute();
}
