ここは旧式の4DドキュメントWebサイトです。最新のアップデートされたドキュメントを読むには新サイトをご利用下さい→ developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
entity.diff( )
|
entity.diff ( entityToCompare {; attributesToCompare} ) -> 戻り値 | ||||||||
引数 | 型 | 説明 | ||||||
entityToCompare | Entity |
![]() |
オリジナルのエンティティと比較するエンティティ | |||||
attributesToCompare | コレクション |
![]() |
比較する属性の名前 | |||||
戻り値 | コレクション |
![]() |
エンティティ間の差異 | |||||
entity.diff( ) メソッドは二つのエンティティの中身を比較し、その差異を返します。
entityToCompare 引数には、オリジナルのエンティティと比較をするエンティティを渡します。
attributesToInspect 引数では、比較する特定の属性を指定することができます。これを渡した場合、比較は指定された属性に対してのみ行われます。省略時には、エンティティ間の全ての差異が返されます。
エンティティの差異は、以下のプロパティを持つオブジェクトのコレクションとして返されます:
プロパティ名 | 型 | 詳細 |
attributeName | 文字列 | 属性名 |
value | 属性の型による | エンティティ内での属性の値 |
otherValue | 属性の型による | entityToCompare内の属性の値 |
コレクションに含まれるのは異なる値を持っていた属性のみです。差異が見つからない場合、entity.diff( ) は空のコレクションを返します。
このメソッドは型がstorage あるいは relatedEntity であるプロパティに適用されます(dataClassAttribute.kind参照)。リレートされたエンティティが更新された場合(外部キーを意味します)、リレートされたエンティティの名前とそのプライマリーキー名がattributeName プロパティに返されます(value および otherValue はリレートされたエンティティ名については空になります)。
比較するどちらかのエンィティがNull である場合、エラーが生成されます。
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) // 全ての差異が返されます
$diff2:=$clone.diff(employee;New collection("firstName";"lastName"))
// firstName と 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 (全ての差異が返されている):
[ { "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]",// Company の Entity 117 "otherValue": "[object Entity]"// Company の Entity 118 } ]
vCompareResult2 ($attributesToInspect についての差異のみ返される)
[ { "attributeName": "firstName", "value": "Karla update", "otherValue": "Karla" }, { "attributeName": "lastName", "value": "Marrero update", "otherValue": "Marrero" } ]
vCompareResult3 ($e1 がtouch した属性のみが返される)
[ { "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]",// Company の Entity 117 "otherValue": "[object Entity]"// Company の Entity 118 } ]
プロダクト: 4D
テーマ: ORDA - エンティティ
初出: 4D v17
ランゲージリファレンス ( 4D v19)
ランゲージリファレンス ( 4D v19.1)
ランゲージリファレンス ( 4D v19.4)
ランゲージリファレンス ( 4D v19.5)
ランゲージリファレンス ( 4D v19.6)
ランゲージリファレンス ( 4D v19.7)
ランゲージリファレンス ( 4D v19.8)