Search code examples
uniqueopen-sourcelsfusion

lsFusion: Uniqueness restriction to a property NULL


Can you tell me how to add a uniqueness restriction to a property so that only one NULL value can be entered? In this case, the restriction does not work for NULL values of id. Checked with the latest versions 4.2 and 5.0.

Here is a sample code from the documentation:

CLASS Book 'Book;
id 'Number' = DATA INTEGER (Book);
book 'Book' (INTEGER i) = GROUP AGGR Book b BY id(b);

Solution

  • For any kind of GROUP operator, the result is always NULL if at least one of the values of the BY clause is NULL. For this reason, standard restriction created by GROUP operator AGGR will not consider empty id values.

    To check for multiple NULL values in this case you have to make a separate CONSTRAINT :

    CONSTRAINT (GROUP SUM 1 IF b IS Book AND NOT id(b)) > 1
        MESSAGE 'Multiple empty values are not allowed';