4D v19entity.diff() |
||||||||||||||
|
4D v19
entity.diff()
|
Eigenschaftsname | Typ | Beschreibung |
attributeName | String | Name des Attributs |
value | Abhängig vom Attributstyp | Wert des Attributs in der Entity |
otherValue | Abhängig vom Attributstyp | Wert des Attributs in entityToCompare |
Nur Attribute mit unterschiedlichen Werten sind in der Collection enthalten. Werden keine Unterschiede gefunden, gibt entity.diff() eine leere Collection zurück.
Die Methode gilt für Eigenschaften der Art storage oder relatedEntity (siehe dataClassAttribute.kind). Wurde eine verknüpfte Entity aktualisiert (d.h. der Fremdschlüssel), werden die Namen der verknüpften Entity und ihres Primärschlüssels als Eigenschaften attributeName zurückgegeben (value und otherValue sind leer für den Namen der verknüpften Entity).
Ist eine der verglichenen Entities Null, wird ein Fehler generiert.
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) // Alle Unterschiede werden zurückgegeben
$diff2:=$clone.diff(employee;New collection"firstName";"lastName"))
// Nur Unterschiede in firstName und lastName werden zurückgegeben
$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 (alle Unterschiede werden zurückgegeben):
[ { "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 von Company "otherValue": "[object Entity]"// Entity 118 von Company } ]
vCompareResult2 (nur Unterschiede in $attributesToInspect werden zurückgegeben)
[ { "attributeName": "firstName", "value": "Karla update", "otherValue": "Karla" }, { "attributeName": "lastName", "value": "Marrero update", "otherValue": "Marrero" } ]
vCompareResult3 (nur Unterschiede in betroffenen Attributen in $e1 werden zurückgegeben)
[ { "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 von Company "otherValue": "[object Entity]"// Entity 118 von Company } ]
Produkt: 4D
Thema: ORDA - Entity
4D Programmiersprache ( 4D v19)
4D Programmiersprache ( 4D v19.1)