This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
entity.toObject( )
|
entity.toObject ( filter {; options} ) -> Result | ||||||||
Parameter | Type | Description | ||||||
filter | String, Collection |
![]() |
Attribute(s) to extract | |||||
options | Longint |
![]() |
dk with primary key: adds the _KEY property; dk with stamp: adds the _STAMP property |
|||||
Result | Object |
![]() |
Object built from the entity | |||||
The entity.toObject( ) method returns an object which has been built from the entity. Property names in the object match attribute names of the entity.
In the filter parameter, you pass the entity attribute(s) to extract. Two syntaxes are allowed:
If filter is specified for attributes of the relatedEntity kind:
If filter is specified for attributes of the relatedEntities kind:
If the filter parameter contains an empty string or "*", the returned object will contain:
In the options parameter, you can pass the dk with primary key and/or dk with stamp selector(s) to add the entity's primary keys and/or stamps in extracted objects.
The following structure will be used throughout all examples of this section:
Without filter parameter:
employeeObject:=employeeSelected.toObject()
Returns:
{ "ID": 413, "firstName": "Greg", "lastName": "Wahl", "salary": 0, "birthDate": "1963-02-01T00:00:00.000Z", "woman": false, "managerID": 412, "employerID": 20, "photo": "[object Picture]", "extra": null, "employer": { // relatedEntity extracted with simple form "__KEY": 20 }, "manager": { "__KEY": 412 } }
Extracting the primary key and the stamp:
employeeObject:=employeeSelected.toObject("";dk with primary key+dk with stamp)
Returns:
{ "__KEY": 413, "__STAMP": 1, "ID": 413, "firstName": "Greg", "lastName": "Wahl", "salary": 0, "birthDate": "1963-02-01T00:00:00.000Z", "woman": false, "managerID": 412, "employerID": 20, "photo": "[object Picture]", "extra": null, "employer": { "__KEY": 20 }, "manager": { "__KEY": 412 } }
Expanding all the properties of relatedEntities:
employeeObject:=employeeSelected.toObject("directReports.*")
{ "directReports": [ { "ID": 418, "firstName": "Lorena", "lastName": "Boothe", "salary": 44800, "birthDate": "1970-10-02T00:00:00.000Z", "woman": true, "managerID": 413, "employerID": 20, "photo": "[object Picture]", "extra": null, "employer": { "__KEY": 20 }, "manager": { "__KEY": 413 } }, { "ID": 419, "firstName": "Drew", "lastName": "Caudill", "salary": 41000, "birthDate": "2030-01-12T00:00:00.000Z", "woman": false, "managerID": 413, "employerID": 20, "photo": "[object Picture]", "extra": null, "employer": { "__KEY": 20 }, "manager": { "__KEY": 413 } }, { "ID": 420, "firstName": "Nathan", "lastName": "Gomes", "salary": 46300, "birthDate": "2010-05-29T00:00:00.000Z", "woman": false, "managerID": 413, "employerID": 20, "photo": "[object Picture]", "extra": null, "employer": { "__KEY": 20 }, "manager": { "__KEY": 413 } } ] }
Extracting some properties of relatedEntities:
employeeObject:=employeeSelected.toObject("firstName, directReports.lastName")
Returns:
{ "firstName": "Greg", "directReports": [ { "lastName": "Boothe" }, { "lastName": "Caudill" }, { "lastName": "Gomes" } ] }
Extracting a relatedEntity with simple form:
$coll:=New collection("firstName";"employer")
employeeObject:=employeeSelected.toObject($coll)
Returns:
{ "firstName": "Greg", "employer": { "__KEY": 20 } }
Extracting all the properties of a relatedEntity:
employeeObject:=employeeSelected.toObject("employer.*")
Returns:
{ "employer": { "ID": 20, "name": "India Astral Secretary", "creationDate": "1984-08-25T00:00:00.000Z", "revenues": 12000000, "extra": null } }
Extracting some properties of a relatedEntity:
$col:=New collection
$col.push("employer.name")
$col.push("employer.revenues")
employeeObject:=employeeSelected.toObject($col)
Returns:
{ "employer": { "name": "India Astral Secretary", "revenues": 12000000 } }
Product: 4D
Theme: ORDA - Entity
Created: 4D v17
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)