Why can a second relation be saved when a reference attribute's maximum cardinality is 1?

Problem

  • A reference attribute, for example an address that links to a Location, is configured with "cardinality": { "minValue": 1, "maxValue": 1 }.
  • A user can still add a second Location to the profile. The cardinality error appears only after it's saved, for example: Attribute <Attribute> must have at most 1 ov value(s), but it has 2.

Cause

Cardinality is enforced differently depending on how the value is added:

  • Attribute editor: in the profile's editing mode, when the maximum cardinality is 1 and the attribute already has a value, the UI hides the + icon, so a second value can't be added.
  • Relations facet or API: adding a Location from a relations facet, or through the API, creates a relationship of the reference attribute's relation type. Reltio doesn't limit the number of relationships of a type out of the box, so the relationship is saved. It then shows as a second value of the reference attribute, and the cardinality validator reports the violation.

Solution

  • Add or change the value through the attribute editor. In editing mode, a second value can't be added to the reference attribute.
  • Block a second relationship on save. To prevent it from every channel, including relations facets and the API, add a custom LCA on the relation type's beforeSave hook. The LCA rejects the save when the entity already has a relationship of that type.

To clear the error on an existing profile, remove the extra value from the reference attribute.

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.