Automatic Type Conversions

Automatic Type Conversions

Sometimes adding new features to an existing application requires updating the type of an existing attribute. A consequence of such a change is a type mismatch between data already stored in the backend and the type requested by the app. A developer can choose between two ways of converting the stored values to the specified type when the Scrivito SDK retrieves such an attribute.

Basic conversions

By default, only the most basic attribute type conversions are enabled. All other type changes will result in the respective empty default value when a mismatching attribute value is retrieved. The active conversions are:

  • datedatetime
  • enumhtml
  • enumstring
  • floatinteger
  • htmlstring
  • multienumstringlist
New in 1.38.0

Optional conversions

This configuration enables automatic conversions from single-value types to a list type, as well as translating from internal links to references and vice versa. For example, an enum attribute can be upgraded to multienum without having to migrate the existing attribute values. After changing an object or widget class attribute from enum to multienum, retrieving a stored value will return a list with one item, or an empty list if the value was stored as null. If a list attribute type is changed to a single-value type, the first item of the stored list becomes the new value. All of the following conversions are available:

  • datedatetime
  • enummultienum
  • enumhtml
  • enumstring
  • enumstringlist
  • floatinteger
  • multienumhtml
  • multienumstring
  • multienumstringlist
  • htmlstring
  • htmlstringlist
  • linklinklist
  • linkreference
  • linkreferencelist
  • linklistreference
  • linklistreferencelist
  • stringstringlist
  • referencereferencelist

Remarks

  1. Indexed links and references are not added or removed automatically. Some type changes can lead to outdated search results for the linksTo and refersTo operators. A manual write-back migration will update the search index.
  2. Values are not reindexed automatically. In particular, a type change from a list to a single-value type can lead to outdated search results for the operators equals, startsWith, isGreaterThan, isLessThan, contains, containsPrefix, matches, and for facets queries. A write-back migration will update the indexed values.
  3. For unsupported conversions, the indexing-related remarks (1) and (2) still apply.
  4. The attribute types not shown in the list (boolean, datalocator, binary and widgetlist) are never converted to or from other types.