Open sstone1 opened 1 year ago
Currently in a Concerto model, it is not possible to define a field as being a set - a collection of unique values.
Allow a model author to define a field as being a set, and at validation time enforce uniqueness on the values in stored in that set.
Imagine a model that backs a multiple choice question in a survey, such as "Which of these fruits do you like?".
The fruits could be modelled as an enumeration:
enum Fruit { o APPLE o PEAR o BANANA o MANGO }
Today, all you can do is model the list of fruits you like as a list:
concept Survey { o Fruit[] fruits }
But there is nothing in the model to say that you only want to allow unique fruit values in the list, so you could have:
{ "$class": "Survey", "fruits": [ "APPLE", "APPLE", "APPLE", "APPLE" ] }
A few syntax options spring to mind:
1) Some kind of generics-like way of expressing a Set type:
Set
concept Survey { o Set<Fruit> fruits }
2) A uniqueness constraint on a list
concept Survey { o Fruit[] fruits unique }
I would suggest that whatever we do, we restrict the type of values in a set to primitive types and enumerations.
I like it, this feature would pair nicely with #447
There is a language design for this feature at https://github.com/accordproject/concerto/wiki/Aggregate-Types-Design-(Working-Draft)
Currently in a Concerto model, it is not possible to define a field as being a set - a collection of unique values.
Feature Request 🛍️
Allow a model author to define a field as being a set, and at validation time enforce uniqueness on the values in stored in that set.
Use Case
Imagine a model that backs a multiple choice question in a survey, such as "Which of these fruits do you like?".
The fruits could be modelled as an enumeration:
Today, all you can do is model the list of fruits you like as a list:
But there is nothing in the model to say that you only want to allow unique fruit values in the list, so you could have:
Possible Solution
A few syntax options spring to mind:
1) Some kind of generics-like way of expressing a
Set
type:2) A uniqueness constraint on a list
I would suggest that whatever we do, we restrict the type of values in a set to primitive types and enumerations.
Context
Detailed Description