英文:
lsFusion: Uniqueness restriction to a property NULL
问题
如何将唯一性限制添加到属性,以确保只能输入一个NULL值?
在这种情况下,该限制不适用于id的NULL值。
已验证最新版本4.2和5.0。
以下是文档中的示例代码:
CLASS Book 'Book;
id 'Number' = DATA INTEGER (Book);
book 'Book' (INTEGER i) = GROUP AGGR Book b BY id(b);
英文:
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);
答案1
得分: 2
以下是您要翻译的内容:
对于任何类型的 GROUP 运算符,如果 BY 子句中的至少一个值为 NULL,结果始终为 NULL。因此,GROUP 运算符 AGGR 创建的标准限制将不考虑空的 id 值。
在这种情况下,要检查多个 NULL 值,您必须创建一个单独的 CONSTRAINT:
CONSTRAINT (GROUP SUM 1 IF b IS Book AND NOT id(b)) > 1
MESSAGE '不允许多个空值';
英文:
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';
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论