4D v19dataClass.fromCollection( ) |
||||||||
|
4D v19
dataClass.fromCollection( )
|
Property | Type | Description |
context | Text | Label for the optimization context applied to the entity selection. This context will be used by the code that handles the entity selection so that it can benefit from the optimization. This feature is designed for ORDA client/server processing; for more information, please refer to the Client/server optimization section. |
We want to update an existing entity. The __NEW property is not given, the employee primary key is given and exists:
C_COLLECTION($empsCollection)
C_OBJECT($emp;$employees)
$empsCollection:=New collection
$emp:=New object
$emp.ID:=668 //Existing PK in Employee table
$emp.firstName:="Arthur"
$emp.lastName:="Martin"
$emp.employer:=New object("ID";121) //Existing PK in the related dataClass Company
// For this employee, we can change the Company by using another existing PK in the related dataClass Company
$empsCollection.push($emp)
$employees:=ds.Employee.fromCollection($empsCollection)
We want to update an existing entity. The __NEW property is not given, the employee primary key is with the __KEY attribute and exists:
C_COLLECTION($empsCollection)
C_OBJECT($emp;$employees)
$empsCollection:=New collection
$emp:=New object
$emp.__KEY:=1720 //Existing PK in Employee table
$emp.firstName:="John"
$emp.lastName:="Boorman"
$emp.employer:=New object("ID";121) //Existing PK in the related dataClass Company
// For this employee, we can change the Company by using another existing PK in the related dataClass Company
$empsCollection.push($emp)
$employees:=ds.Employee.fromCollection($empsCollection)
We want to simply create a new entity from a collection:
C_COLLECTION($empsCollection)
C_OBJECT($emp;$employees)
$empsCollection:=New collection
$emp:=New object
$emp.firstName:="Victor"
$emp.lastName:="Hugo"
$empsCollection.push($emp)
$employees:=ds.Employee.fromCollection($empsCollection)
We want to create an entity. The __NEW property is True, the employee primary key is not given:
C_COLLECTION($empsCollection)
C_OBJECT($emp;$employees)
$empsCollection:=New collection
$emp:=New object
$emp.firstName:="Mary"
$emp.lastName:="Smith"
$emp.employer:=New object("__KEY";121) //Existing PK in the related dataClass Company
$emp.__NEW:=True
$empsCollection.push($emp)
$employees:=ds.Employee.fromCollection($empsCollection)
We want to create an entity. The __NEW property is omitted, the employee primary key is given and does not exist:
C_COLLECTION($empsCollection)
C_OBJECT($emp;$employees)
$empsCollection:=New collection
$emp:=New object
$emp.ID:=10000 //Unexisting primary key
$emp.firstName:="Françoise"
$emp.lastName:="Sagan"
$empsCollection.push($emp)
$employees:=ds.Employee.fromCollection($empsCollection)
In this example, the first entity will be created and saved but the second will fail since they both use the same primary key:
C_COLLECTION($empsCollection)
C_OBJECT($emp;$emp2;$employees)
$empsCollection:=New collection
$emp:=New object
$emp.ID:=10001 // Unexisting primary key
$emp.firstName:="Simone"
$emp.lastName:="Martin"
$emp.__NEW:=True
$empsCollection.push($emp)
$emp2:=New object
$emp2.ID:=10001 // Same primary key, already existing
$emp2.firstName:="Marc"
$emp2.lastName:="Smith"
$emp2.__NEW:=True
$empsCollection.push($emp2)
$employees:=ds.Employee.fromCollection($empsCollection)
//first entity is created
//duplicated key error for the second entity
Product: 4D
Theme: ORDA - DataClass
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)