Entities

What is an entity?

In a general sense an entity is any singular, identifiable and separate object. In One ERP entities are used to model and manage business data and are defined by: (1) an unique name, (2) a set of properties and (3) a set of relationships with other entities. Examples of entities: product, customer, invoice etc.

Conceptually, an entity is like a database table, and the properties correspond to the table columns. Creating an entity record (or, simply a record) in One ERP is like adding a row in a database table. There are three types of entities: read-only system, writable system, and custom. When developing applications in One ERP you will be working with custom entities. System entities are used by One ERP to handle internal operations such as metadata, security and workflows. System entities cannot be unpublished.

In this article

Entity metadata

The metadata for a One ERP instance contains the definitions for the structure of the entities. For each entity the metadata contains information about the entity, its properties and its relationships.

To view the metadata for an entity click the Develop app, and then click on the Customization sets menu. In the page that opens, under the Search section, enter in the Entity field the name of the entity. Click the Search button.

Best practice

An entity name should be a singular noun.

Properties

A property is identified by a name and has a type. The type describes what kind of data can be stored. There are two types of properties: system and custom. System properties are handled automatically by One ERP for managing entity record identity, entity record ownership and date/time of the create and update operations.

The system properties are:

Property name

Type

Description

Property name

Type

Description

key

Integer

the identity (or key) of the entity record

date_created 

Datetime

the date and time when the entity was created

date_updated 

Datetime

the date and time of the last entity update

id_user 

Integer relationship

identifies the user that owns the entity

id_business_unit 

Integer relationship

identifies the business unit of the user that owns the entity

id_organization 

Integer relationship

identifies the organization of the user that owns the entity

System properties are created automatically and cannot be deleted or changed.

Custom properties can be created at will with the following limitations on their name:

  1. Property names are case sensitive and unique

  2. The property name cannot start with a number or with the "id_"

  3. The property name can contain only ascii letters ([a-zA-Z]), numbers and the character "_"

Property types

The following property types are available in One ERP:

Type

Dimension

MySQL

SQL Server

PGSQL

Oracle 12c

Type

Dimension

MySQL

SQL Server

PGSQL

Oracle 12c

String

255 characters

VARCHAR(255)

NVARCHAR(255)

VARCHAR( 255 )

NVARCHAR2(255)

String31

2^31 characters

LONGTEXT

TEXT

TEXT

LONG

Integer



INTEGER

INT

NUMERIC(20, 0)

NUMERIC(20, 0)

Decimal

20 digits and 4 decimal places

DECIMAL(20,4)

DECIMAL(20,4)

NUMERIC(20, 4)

NUMERIC(20, 4)

Datetime

-

DATETIME

DATETIME

TIMESTAMP

DATE //TIMESTAMP

Binary

2^24 bytes.

MEDIUMBLOB

VARBINARY

BYTEA

BLOB

Relationships

relationship is identified by a name and has a type, property name, foreign entity and a foreign property name. The type describes how the data is related. There are two types of relationshipssystem and custom. System relationships are handled automatically by One ERP for managing entity record identity, entity record ownership.

To simply descriptions we will describe relationships as sentences with the following structure:

define relationshipName of type between left-side entity and right-side entity

From hereon we will call the rel

Relationship notation

relationshipName = localEntity type to foreignEntity on property and foreignProperty

The structure of a relationship:

Item

Description

Item

Description

Name

The name of the relationship. Globally unique.

Type

The type of the relationship

Entity

The entity on the left-side of the relationship

Property name

The property for the key of entity on the right-side on the entity on the left-side of the relationship

Foreign entity

The entity on the right-side of the relationship

Foreign property name

The property for the foreign key on the Many-To-Many???

In One ERP there are four types of relationships: One-To-Many and Many-To-One, Parent-Child and Child-Parent, Many-To-Many, One-To-One. Many-To-Many and One-To-One are implemented but cannot be used and are reserved for future use.

The system relationships are:

Name

Entity

Type

Property name

Foreign entity

Description

Name

Entity

Type

Property name

Foreign entity

Description

[entityName]_user

[entityName]

Many-To-One

id_user

user

identifies the user that owns the entity

user

One-To-Many



[entityName]

[entityName]_business_unit

[entityName]

Many-To-One

id_business_unit

business_unit

identifies the business unit of the user that owns the entity

business_unit

One-To-Many



[entityName]

[entityName]_organization

[entityName]

Many-To-One

id_organization

organization

identifies the organization of the user that owns the entity

organization

One-To-Many



[entityName]

System relationships are created automatically and cannot be deleted or changed.

Custom relationships can be created at will with the following limitations on their Name:

  1. Relationship names are case sensitive and globally unique

  2. The relationship name cannot start with a number

  3. The relationship name can contain only ASCII letters ([a-zA-Z]), numbers and the character "_"

and the following limitations on their Type:

  1. Only one relationship of the same Type  same Foreign entity  and same Property name can be created, regardless of Name.

One-To-Many (1:n) and Many-To-One (n:1)

When creating a One-To-Many relationship between two entities the following will happen: 

  1. The relationship will be created on the entity corresponding to the "Many" part;

  2. A reversed relationship (Many-To-One) will be created on the entity corresponding to the "One" part;

  3. A property that holds the key, of the entity corresponding to the "One" part, will be created on the entity corresponding to the "Many" part.

The previous is valid also when creating a Many-To-One relationship.

This type of relationship can be created multiple times between the same entities or with the same entity on both parts. In this case the relationships must be distinguished by different Names and must be on different Property names.

Example of Many-To-One relationship

Let's create another 2 entites called purchase_invoice and supplier. The entity purchase_invoice will have a Many-To-One (n:1) relationship with the supplier entity.

The purchase_invoice has the next properies:

  • date of type: datetime

  • number of type: string

  • terms of type: string

The supplier entity has the next properties:

  • name of type: string

  • address of type: string

The n:1 relationship between purchase_invoice and supplier will be called purchase_invoice_supplier.

Best practice

The user can choose what kind of relationship he wants to create One-To-Many or Many-To-One. It is recomanded that after he has chosen one of this relationships, to create the same type of relationship everywhere in the project.

Parent-Child (p:c) and Child-Parent (c:p)

From structural point of view this types of relationships are identical with One-To-Many and Many-To-One relationships. The difference resides in the fact that they are managed in the same life cycle and not separately. This means that child entities are not saved or updated separately but within parent entity. 

Example of Parent-Child relationship

Here we defined another entity called purchase_invoice_item. The entity purchase_invoice , that we created in the last example, will be in a Parent-Child (p:c) relationship with this new entity.

The purchase_invoice_item has the next properties:

  • quantity of type: decimal

  • unit_price of type: decimal

  • amount of type: decimal

The p:c relationship between purchase_invoice and purchase_invoice_item will be named purchase_invoice_purchase_invoice_item.

If we make changes to one of the purchase_invoice_item of a purchase_invoice, to save those changes we will have to save the purchase_invoice that contained that item.

Many-To-Many (n:n)

This kind of relationship creates into the database a table with the primary keys of the both entities.

One-To-One (1:1)

In One-To-One relationship a record coresponding to the table of one of the two entities is associated with one and only one record of the other entity.

Lifecycle of entity records

Understanding the life cycle of entity records is very important.

All properties and relationships are updated in the same time. In contrast with database table you cannot update only one single property for an entity. 

When designing the data model you must take in account all the life cycle events of a entity not just the structure.

Creating

Reading

Updating

Deleting

Entity ownership