Entities Examples - dinmax/letrest GitHub Wiki
Entities Examples and Descriptions
These are some examples of how to configure the attributes on the entity to get diferrent results. It is important to remember the following attributes:
- Mapping, changes how or which information is shown
- FK, changes how to access to the information of other tables
Simple
{
"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"
}
],
"service": {
"all": {},
"get": {}
},
"schema": null
}
The objects handled by this entity will have the following format
{
"taxid": "1",
"name": "IVA"
}
To add a taxtype attribute to to this entity, simply add the field to the mapping on the entity
{
...
"mapping": [
{
"field": "taxid@tax",
"attribute": "tax@taxid",
"external": true
},
{
"field": "name@tax",
"attribute": "tax@name"
},
{
"field": "taxtypeid@tax",
"attribute": "tax@taxtypeid",
"external": true
}
]
...
}
{
"taxid": "1",
"name": "IVA",
"taxtypeid": "2"
}
Basic Join
Here is an example of tax.json entity. It also brings information from another table taxtype.
IMPORTANT If no type of join is described the default one is a INNER JOIN and only the data related to taxtype will be search for.
{
"name": "tax",
"path": "/tax",
"table": "tax",
"weight": 0,
"pk": "taxid",
"fk": {
"taxtypeid": {
"relation": "taxtypeid@taxtype",
"field": "taxtypeid",
"type": "object",
"value": "taxtype.taxtypeid"
}
},
"mapping": [
{
"field": "taxid@tax",
"attribute": "taxid",
"external": true
},
{
"field": "name@tax",
"attribute": "name"
},
{
"field": "taxtypeid@tax",
"attribute": "taxtypeid",
"external": true
},
{
"field": "taxtypeid@taxtype",
"attribute": "taxtype@taxtypeid",
"external": true
},
{
"field": "name@taxtype",
"attribute": "taxtype@name",
"external": true
}
],
"service": {
"all": {}
}
}
Object
{
"taxid": "1",
"name": "Curtu",
"taxtypeid": "1",
"taxtype": {
"taxtypeid": "1",
"name": "Simple"
}
}
Left Join
When bringing information from other tables the main table isn't always related to that information therefore, is necessary to specify the type of relation on the FK. This is done with the attribute jointype.
When doing a JOIN and bringing information from the table taxinterest, the table tax doesn't always have an interest.
{
"name": "tax",
"path": "/tax",
"table": "tax",
"weight": 0,
"pk": "taxid",
"fk": {
"taxtypeid": {
"relation": "taxtypeid@taxtype",
"field": "taxtypeid",
"type": "object",
"value": "taxtype.taxtypeid"
},
"taxinterestid": {
"relation": "taxinterestid@taxinterest",
"field": "taxinterestid",
"type": "object",
"value": "taxinterest.taxinterestid",
"jointype": "left"
}
},
"mapping": [
{
"field": "taxid@tax",
"attribute": "taxid",
"external": true
},
{
"field": "name@tax",
"attribute": "name"
},
{
"field": "taxtypeid@tax",
"attribute": "taxtypeid",
"external": true
},
{
"field": "taxtypeid@taxtype",
"attribute": "taxtype@taxtypeid",
"external": true
},
{
"field": "name@taxtype",
"attribute": "taxtype@name",
"external": true
},
{
"field": "taxinterestid@taxinterest",
"attribute": "taxinterest@taxinterestid",
"external": true
},
{
"field": "name@taxinterest",
"attribute": "taxinterest@name",
"external": true
},
{
"field": "rate@taxinterest",
"attribute": "taxinterest@rate",
"external": true
}
],
"service": {
"all": {}
}
}
Objects
{
"taxid": "1",
"name": "tax 1",
"taxtypeid": "1",
"taxtype": {
"taxtypeid": "1",
"name": "Simple"
},
"taxinterest": {
"taxinterestid": null,
"name": null,
"rate": null
}
},
{
"taxid": "2",
"name": "tax 2",
"taxtypeid": "2",
"taxtype": {
"taxtypeid": "2",
"name": "Complex"
},
"taxinterest": {
"taxinterestid": "1",
"name": "high",
"rate": "10"
}
}
Other Table
Here the taxinterest is not related to the tax table but to the taxtype, so it's necessary to specify from which table the data will be joined using the source attribute on the FK.
"fk":{
"taxtypeid": {
...
},
"taxinterestid": {
"relation": "taxinterestid@taxinterest",
"field": "taxinterestid",
"type": "object",
"value": "taxinterest.taxinterestid",
"jointype": "left",
"source": "taxtype"
}
}
Objects
{
"taxid": "1",
"name": "tax 1",
"taxtypeid": "1",
"taxtype": {
"taxtypeid": "1",
"name": "Simple"
},
"taxinterest": {
"taxinterestid": null,
"name": null,
"rate": null
}
},
{
"taxid": "2",
"name": "tax 2",
"taxtypeid": "2",
"taxtype": {
"taxtypeid": "2",
"name": "Complex"
},
"taxinterest": {
"taxinterestid": "1",
"name": "high",
"rate": "10"
}
}