Working with entities
This chapter covers the syntax and examples for working with entities. In Workflow language entities are first class citizens.
Creating entities
CREATE [entityName]
Creates and returns a new entity. The entity will have a key only after the PUT statement.
Here is an example on how to create an entity:
//Create the entity
var c = CREATE color;
//Set the properties
c.code = "#ff2390";
//Save the entity
PUT c;
CREATE CHILD [entityVariable] [relationshipName]
Creates a new child entity and adds it to the named relationship on the parent entity.
Here is an example on how to create an entity with children:
//Creates an instance of the 'invoice' entity
var i = CREATE invoice;
//Set the properties
i.number = "1234";
/**
* Create one child on the 'i' variable
* (which is an instance of the 'invoice' entity) for the
* 'invoice_invoice_item' relationship
*/
var item = CREATE CHILD i invoice_invoice_item;
//Set the child properties
item.id_product = 100;
item.quantity = 50.4;
//Notice that we do not use PUT for the child entity
//Save the entity
PUT i;
Reading entities
GET [entityName] (key as int)
Reads an entity.
Here is an example on how to read & update an entity:
//Create the entity
var c = GET color(1);
//Read the properties
var colorCode = c.code;
//Set the properties
c.code = "#ff2390";
//Update the entity
PUT c;
CHILD [entityVariable] [relationshipName]
Here is an example on how to iterate over the children of a given relationship:
Tracking changes
ORIGINAL [entityVariable].[propertyName]
Returns the original value of the property (before it was updated).
The original value of a property can be read as follows:
The ORIGINAL
keyword is especially useful when the update on data occurs in the interface:
CHILD DELETED [entityVariable] [relationshipName]
Here is an example on how to iterate over the deleted children of a given relationship:
Deleting entities
DELETE [entityVariable]
DELETE [entityName] (key as int)
DELETE CHILD [entityVariable] [relationshipName] [childEntityVariable]
Deletes an entity.
This example deletes the color entity, by first reading it:
This example deletes the color entity directly, by key:
This example deletes the color_item child entity: