keyed_array_delta
A keyed_array_delta
is a type of delta that
creates, updates, or deletes objects in an array, where objects can be identified by an ID.
A keyed_array_delta
can be used on the problem.routes, route.breaks, or job.loads fields, for example.
If multiple operations are specified, the fields are applied in the following order: unassign
, assign
, assign_template
.
When modifying a top-level collection (for example, problem.routes),
one and only one of unassign
, assign
, or assign_template
can be specified,
as this allows API clients to reliably distinguish between creates, updates, and deletes of top-level entities.
Name | Type | Description |
---|---|---|
$collection | string | Required. Must be "keyed_array" for a keyed_array_delta . |
$create | boolean | Optional. Defaults to true . If the delta is attempting to modify a non-existent object , create it first. |
$path | string | Required on top-level deltas. The JSON path to modify. See Paths for a list of valid paths. |
assign | delta[] | Optional. Create or update entities. |
assign_template | delta | Optional. Bulk create or update entities, using the IDs specified by ids . |
ids | delta[] | Optional. The IDs to use with assign_template . |
key | string | Optional. Defaults to id . The field to use as the key. For example, when modifying job.loads, the key is metric . |
unassign | string[] | Optional. Remove the entities from the problem matching these ids. |
Examples
A revision for modifying route.load_capacities
and route.breaks using a keyed_array_delta
:
{
"deltas": [{
"$path": ["route"],
"$collection": "keyed_array",
"ids": ["route0", "route1"],
"assign": {
"load_capacities": {
"$collection": "keyed_array",
"key": "metric",
"assign": [{
"metric": "kg",
"amount": 123,
}],
},
"breaks": {
"$collection": "keyed_array",
"key": "id",
"assign": [{
"id": "lunch",
"start": "13:00",
}],
"unassign": ["dinner"], // bulk remove dinner break
},
},
}]
}