Skip to main content

Advanced

You can do a lot more with Model Definitions besides defining references and properties. Some of the most useful features are explained on this page:


{
"key": "dispatchOverviewModel",
"keyProperty": "someOtherKey",
"supportsAutoCreation": true,
"autoGenerateKey": true,
"data": [],
"valueMappings": [],
"references": [...],
"properties": [...]

keyProperty​

You can specify an alternative primary key property other than the default key to identify your data entries. Internally we map it to the key property to keep everything stable and predictable.

data​

You can also put data related to your model directly in the data attribute. This is especially useful, if you only need some static data for this specific model.

supportsAutoCreation​

If you enable supportsAutoCreation, dcupl will try to create new entries for referenced models. If the referenced value is a key (or keys) dcupl will create an empty shell for the referenced value. If the referenced value is an object containing a valid key property it will try to add this entry to the model.

autoGenerateKey​

Works together with supportsAutoGeneration. If there is no key property present on the JSON, dcupl will generate one.

valueMappings​

A value mapping during data processing. You can fix potential data errors (undefined or falsy values) or just remap data the way you like.

A special operator string here is $dcupl_falsy as a combination for empty string (""), undefined and null. But you can put any value in there you want.

"valueMappings": [
{
"attributes": ["someProperty"],
"values": [
{
"from": ["$dcupl_falsy"],
"to": "false"
}
]
}
],

aggregations​

Properties and filters can be marked for aggregation by setting the property aggregation to true.

typeaggregation
referenceA reference will be aggregated by it's key property.
stringA string will be aggregated by it's value.
int/floatA number aggregation calculates the average, count and sum of its value

Attribute Origin (alias)​

You can rename (alias) your input data and map it to a new attribute using the origin property in your model definitions. This is also helpful if you want to apply different transformers to the same input data.

// rename the input property "firstname" to your model property "name"
{
"key": "name",
"origin": "firstname",
"type": "string",
"filter": true
}

Expressions​

Combine multiple properties to one using expressions

[
{
"key": "a",
"type": "string"
},
{
"key": "b",
"type": "string"
},
{
"key": "ab",
"type": "string",
"expression": "${a} - ${b}"
}
]