An asset field may be a container of another asset. There are two kinds of such container:
A partition is used when an asset belongs to one and exactly one other asset. For example, say that the collection of cars is organized in different fleets so that one car asset belongs to only one fleet asset:
cars: partition<car>;/* a car asset belongs to one fleet asset */
Indeed, if the above was possible, the car asset YS3ED48E5Y3070016 would not belong to any fleet, which is contrary to the idea of partition. Thus in this situation, archetype generates the following error:
Cannot access asset collection: asset car is partitionned by field(s)(cars).
The proper way to modify the car collection is through the cars partition of a fleet asset which provides the following instructions:
The above fails if a key is not present in the car collection. It means that you can only add an existing asset reference in an aggregate.
The add instruction adds a key to an aggregate. It fails if the base collection does not contain that key: in the example below, the instruction fails if "YS3ED48E5Y3070016" is not found in the car collection. It also fails if "f01" is not found in the driver collection.
driver["f01"].drives.add("YS3ED48E5Y3070016");/* fails if car collection
does not contain YS3ED48E5Y3070016 */
The remove instruction removes a reference from an aggregate. It fails if the key is not in the base collection: in the example below, the instruction fails if "f01" is not found.