4D v19entity.diff( ) |
||||||||||||||
|
4D v19
entity.diff( )
|
Property name | Type | Description |
attributeName | String | Name of the attribute |
value | Depends on attribute type | Value of the attribute in the entity |
otherValue | Depends on attribute type | Value of the attribute in entityToCompare |
Only attributes with different values are included in the collection. If no differences are found, entity.diff( ) returns an empty collection.
The method applies for properties whose kind is storage or relatedEntity (see dataClassAttribute.kind). In case a related entity has been updated (meaning the foreign key), the name of the related entity and its primary key name are returned as attributeName properties (value and otherValue are empty for the related entity name)
If one of the compared entities is Null, an error is raised.
C_COLLECTION($diff1;$diff2)
employee:=ds.Employee.query("ID=1001").first()
$clone:=employee.clone()
employee.firstName:="MARIE"
employee.lastName:="SOPHIE"
employee.salary:=500
$diff1:=$clone.diff(employee) // All differences are returned
$diff2:=$clone.diff(employee;New collection"firstName";"lastName"))
// Only differences on firstName and lastName are returned
$diff1:
[ { "attributeName": "firstName", "value": "Natasha", "otherValue": "MARIE" }, { "attributeName": "lastName", "value": "Locke", "otherValue": "SOPHIE" }, { "attributeName": "salary", "value": 66600, "otherValue": 500 } ]
$diff2:
[ { "attributeName": "firstName", "value": "Natasha", "otherValue": "MARIE" }, { "attributeName": "lastName", "value": "Locke", "otherValue": "SOPHIE" } ]
vCompareResult1:=New collection
vCompareResult2:=New collection
vCompareResult3:=New collection
$attributesToInspect:=New collection
$e1:=ds.Employee.get(636)
$e2:=ds.Employee.get(636)
$e1.firstName:=$e1.firstName+" update"
$e1.lastName:=$e1.lastName+" update"
$c:=ds.Company.get(117)
$e1.employer:=$c
$e2.salary:=100
$attributesToInspect.push("firstName")
$attributesToInspect.push("lastName")
vCompareResult1:=$e1.diff($e2)
vCompareResult2:=$e1.diff($e2;$attributesToInspect)
vCompareResult3:=$e1.diff($e2;$e1.touchedAttributes())
vCompareResult1 (all differences are returned):
[ { "attributeName": "firstName", "value": "Karla update", "otherValue": "Karla" }, { "attributeName": "lastName", "value": "Marrero update", "otherValue": "Marrero" }, { "attributeName": "salary", "value": 33500, "otherValue": 100 }, { "attributeName": "employerID", "value": 117, "otherValue": 118 }, { "attributeName": "employer", "value": "[object Entity]",// Entity 117 from Company "otherValue": "[object Entity]"// Entity 118 from Company } ]
vCompareResult2 (only differences on $attributesToInspect are returned)
[ { "attributeName": "firstName", "value": "Karla update", "otherValue": "Karla" }, { "attributeName": "lastName", "value": "Marrero update", "otherValue": "Marrero" } ]
vCompareResult3 (only differences on $e1 touched attributes are returned)
[ { "attributeName": "firstName", "value": "Karla update", "otherValue": "Karla" }, { "attributeName": "lastName", "value": "Marrero update", "otherValue": "Marrero" }, { "attributeName": "employerID", "value": 117, "otherValue": 118 }, { "attributeName": "employer", "value": "[object Entity]",// Entity 117 from Company "otherValue": "[object Entity]"// Entity 118 from Company } ]
Product: 4D
Theme: ORDA - Entity
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)