4D v18entity.diff( ) |
||||||||||||||
|
4D v18
entity.diff( )
|
Nome de Propriedade | Tipo | Descrição |
attributeName | String | Nome do atributo |
valor | Depende do tipo do atributo | Valor do atributo na entidade |
otherValue | Depende do tipo de atributo | Valor do atributo na entidadeAComparar |
Só atributos com valores diferentes são incluidos na coleção. Se nenhuma diferença for encontrada, entity.diff( ) retorna uma coleção vazia.
O método aplica para propriedades cujo tipo é armazenamento ou entidadeRelacionada (ver dataClassAttribute.kind). No caso de uma entidade relacionada tenha sido atualizada (ou seja uma chave estrangeira -foreign), o nome da entidade relacionada e o nome da chave primária são retornados como propriedades nomeAtributo (valor e outroValor são vazias para o nome da entidade relacionada)
Se uma das entidades comparadas for Null, um erro é levantado.
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 as diferenças são retornadas
$diff2:=$clone.diff(employee;New collection"firstName";"lastName"))
// Só diferenças em firstName e lastName são retornadas
$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]",// Entidade 117 de Company "otherValue": "[object Entity]"// Entidade 118 de Company } ]
vCompareResult2 (só diferenças em $attributesToInspect são retornadas)
[ { "attributeName": "firstName", "value": "Karla update", "otherValue": "Karla" }, { "attributeName": "lastName", "value": "Marrero update", "otherValue": "Marrero" } ]
vCompareResult3 (só diferenças em atributos $e1 touched são retornadas)
[ { "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]",// Entidade117 de Company "otherValue": "[object Entity]"// Entidade 118 de Company } ]
Produto: 4D
Tema: ORDA - Entidade
Manual de linguagem 4D ( 4D v18)