【发布时间】:2021-02-09 16:57:17
【问题描述】:
我有一个实体如下:
shape
--------------
?float height
?float width
?float depth
我想将对象的创建限制为唯一值,包括空值的组合 例如:
shape1: 1,1,1
shape2: 1,null,null
shape3: 1,1,null
shape4: null,null,null
...
我已尝试添加 UniqueEntity 约束来执行此操作:
* @UniqueEntity(
* fields={"height","width","depth"}
* )
但只有在传递实际值时才会触发验证:
id height width depth
1 1 1 1 <- triggers constraint if inserted twice
2 1 null null <- does not trigger constraint if inserted twice
3 null null null <- does not trigger constraint if inserted twice
4 1 1 null <- triggers constraint if inserted twice
我该如何解决这个问题?
ignoreNull 将完全忽略空值,或者,如果设置为 =false,将在第一个空值之后触发,再次完全忽略该字段。
【问题讨论】: