4D v17.4entity.diff( ) |
||||||||||||||
|
4D v17.4
entity.diff( )
|
Nombre de la propiedad | Tipo | Descripción |
attributeName | Cadena | Nombre del atributo |
value | Depende del tipo de atributo | Valor del atributo en la entidad |
otherValue | Depende del tipo de atributo | Valor del atributo en entidadAComparar |
Solo los atributos con diferentes valores están incluidos en la colección. Si no se encuentran diferencias, entity.diff( ) devuelve una colección vacía.
El método aplica a las propiedades cuyo tipo es storage o relatedEntity (ver dataClassAttribute.kind). En el caso de que una entidad relacionada se haya actualizado (llave foránea), el nombre de la entidad relacionada y su nombre de llave primaria se devuelven como propiedades attributeName (value y otherValue están vacías para los nombres de entidad relacionados)
Si una de las entidades comparadas es Null, se genera un error.
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) // Todas las diferencias se devuelven
$diff2:=$clone.diff(employee;New collection"firstName";"lastName"))
// Sólo se devuelven las diferencias en firstName y lastName
$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 (todas las diferencias se devuelven):
[ { "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 (solo se devuelven las diferencias en $attributesToInspect)
[ { "attributeName": "firstName", "value": "Karla update", "otherValue": "Karla" }, { "attributeName": "lastName", "value": "Marrero update", "otherValue": "Marrero" } ]
vCompareResult3 (solo se devuelven las diferencias en $e1 touched attributes)
[ { "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]",// Entidad 117 de Company "otherValue": "[object Entity]"// Entidad 118 de Company } ]
Producto: 4D
Tema: ORDA - Entity
Manual de lenguaje 4D ( 4D v17)
Manual de lenguaje 4D ( 4D v17.1)
Manual de lenguaje 4D ( 4D v17.2)
Manual de lenguaje 4D ( 4D v17.3)
Manual de lenguaje 4D ( 4D v17.4)