Question. Suppose that I have the following collection types:
- Customers
- Orders
and I want to store the Customer ID and the Customer Name on each Order…
If the customer then updates his Name, how is it possible (if at all) to update the customer’s name on all of his orders - in a single atomic transaction?
Answer. For this situation, you would have two content types - Customer and Order. One good way to address this is to utilize an association between the two. You could declare an association type (say, CustomerHasOrder). Association types are similar to content types except that they are used to describe the schema and behavior of relationships in the content graph.
In this case, your CustomerHasOrder association could have the f:property-mapping feature on it. The f:property-mapping feature is configured for the CustomerHasOrder association by adding a "mandatoryFeatures" property to the schema. It might look like this:
"mandatoryFeatures": { "f:property-mapping": { "mappings": [{ "from": "target", "fromProperty": "id", "toProperty": "customerId" }] } }
This tells the association type that any associations of type CustomerHasOrder should make sure to propagate property values from the source to the target. In this case, the "id" property from the Customer (source) will be written into the "customerId" property on the Order (target). All you have to do is create a Customer, create an Order and link them with an association of type CustomerHasOrder.
This can really be done in any order. If you create the association afterwards, the properties are synced when the association links up in the graph. Afterwards, if you update the Customer, the Order will be updated in the same transaction. If you later unlink the association, the properties on source and target will be left alone, they'll just no longer be linked and automatically updated.
There are other ways to do this as well. However, the ability of Cloud CMS to inject behaviors onto instances and content types is the easiest way to do this. It runs in transaction and keeps your graph consistent. The f:property-mapping feature is provided to make this as simple as possible (and entirely configuration driven).