Modify a resource property: Multiple child

You can modify a property of type of type link to several resources (known as childmulti or multiple child) by passing an array of identifiers in the JSON object. For a modification by property, we will pass several values for the property, one per identifier. However, you can manipulate its content more easily, by adding, deleting, etc. To do this, pass a JSON object, with two properties:

  • $values (or $value): a single value or an array of values (almost always identifiers)

  • $mode: the modification mode

If $mode is missing, the default mode is REPLACE.

Mode REPLACE

In this mode, In this mode, the current value of the property is replaced by the one passed in parameter (in $values). This is the default mode.

These three examples do the same thing:

"property": { "$values": [3, 4, 5], "$mode": "replace" }
"property": { "$values": [3, 4, 5], }
"property": [3, 4, 5]

The property will be modified like this:

  • before: [1, 2, 3]

  • after: [3, 4, 5]

Mode APPEND

In this mode, the values from $values array are added at the end of current value.

Example:

  • before: [1, 2, 3]

  • after: [1, 2, 3, 3, 4, 5]

Mode REMOVE

In this mode, the values from $values are removed from the current value.

Example:

  • before: [1, 2, 3]

  • after: [1, 2]

Mode RETAIN

In this mode, only those values that are in both $values and the current value are retained.

Example:

  • before: [1, 2, 3]

  • after: [3]

Mode APPENDNEW

In this mode, the values from $values array are added at the end of current value, if they are not already there.

Example:

  • before: [1, 2, 3]

  • after: [1, 2, 3, 4, 5]

Mode REMOVEFIRST

In this mode, we delete the first occurrence of each value we have in $values.

Example:

  • before: [1, 2, 3, 1, 4, 5]

  • after: [2, 3, 1, 5]

Mode REMOVELAST

In this mode, we delete the last occurrence of each value we have in $values.

Example:

  • before: [1, 2, 3, 1, 4, 5]

  • after: [1, 2, 3, 5]

Mode CLEAR

In this mode, we delete all the current values ($values is ignored, and can be omitted, or empty, or null).

Mode MAP

In this mode, we replace the identifiers using a mapping system old identifier=new identifier. So the $values must contains mappings, as JSONObject, where properties are ids to be replaced, and values corresponding new id to replace with.

Example:

  • before: [1, 2, 3, 4, 5]

  • after: [7, 6, 3, 4, 5]

The different mappings are merged before being applied, from left to right, with priority to the first occurence.

Example:

  • before: [1, 2, 3, 4, 5]

  • after: [6, 7, 8, 11, 5]

Mode MULTIPLE

This mode allows you to apply several commands sequentially. You just have to indicate several commands in an array.

  • before: [1, 2, 3, 4, 5]

  • after: [4, 5, 6, 7]

Â