Entities - dinmax/letrest GitHub Wiki

Let Rest Entities

Defines the entities that are going to be exposed to the REST Api.

Config

The entities files must be on the directory config/letrest/entities/, each file represents a single entity and the denomination must be name.json, where name is in lowercase, with characters and '-' (slash).

Format

The file format is a traditional JSON with some attributes.

Here is an example of a simple tax.json entity.

	{
	"name": "tax",
	"path": "/tax",
	"table": "tax",
	"weight": 0,
	"pk": "taxid",
	"fk":{},
	"mapping": [
		{
			"field": "taxid@tax",
			"attribute": "tax@taxid",
			"external": true
		},
		{
			"field": "name@tax",
			"attribute": "tax@name"
		},
		{
			"field": "taxtypeid@tax",
			"attribute": "tax@taxtypeid",
			"external": true
		}
	],
	"service": {
		"all": {},
		"get": {}
	},
	"schema": null
}

The objects handled by this entity will have the following format

{
	"taxid": "1",
	"name": "IVA",
	"taxtypeid": "2"
}

Entity Attributes

Below you will find the attributes details needed to configure the entities on the platform and examples of each of them.

name

Each entity will have a unique name marked as an attribute. It is recommended that the name of the attribute is the same as the name of the file.

path

Path to access the defined entity and execute the services. It is also recommended that its name matches the names of the file and of the attribute.

table

Indicates wich table must be used to interact when the services are called. The table will be used as the base for the queries and the modifications will be performed on it.

pk

This field indicates the primary key of the entity (on the table) and is mandatory. The importance of this field is presented when performing modifications or inserts services.

fk

It will define all the foreign keys that are related to this entity. This FK will have different behaviours depending on the configuration. Basically, each fk defines a relation with other tables when executing the services.

  • relation field@table, determines the field and table of the FK to be used when performing the join
  • field represents the field on the entity table which will be used on the JOIN
  • type determines if the value used to insert or update should come from the OBJECT or from the URL.
  • value value to be used to insert or update
  • jointype determines the type of JOIN to be used, the default one is INNER
  • source determines other table to do the JOIN, against relation table, instead of the entity table
  • alias used to give the table on relation another name
  • comparator comparator to use on the JOIN, the default is =
  • sql extra field to use when using security on updates

mapping

service

See [Entities Service] (https://github.com/dinmax/letrest/wiki/Entities-Service)