假设一个简单的Grails领域类:Grails领域类:多列
class Account {
String countryId;
String userName;
String password;
static constraints = {
...???...
}
}
它要求用户名是唯一的特定 countryId,因此必须有一个独特 contraint在两列。如何在限制中表达这个定义?
假设一个简单的Grails领域类:Grails领域类:多列
class Account {
String countryId;
String userName;
String password;
static constraints = {
...???...
}
}
它要求用户名是唯一的特定 countryId,因此必须有一个独特 contraint在两列。如何在限制中表达这个定义?
userName(unique: ['countryId'])
可以包括构成必须在用户名中的“独一无二”的约束需要考虑的其他属性阵列中的许多其他属性。
因此,举例来说,如果你想使userName
一个countryId
和provinceId
中是唯一的,将是这样的:
userName(unique: ['countryId', 'provinceId']
你与grails摇滚 –
在grails 3中它被写为“userName unique:'countryId'” http://docs.grails.org/latest/ref/Constraints /unique.html –
@CarlosParraga这只是同一事物的变体。同样的语法也可以用于3.x之前的Grails版本。 –
我在浏览网页,特别是没有计算器找到答案。最后,我在[Grails参考](http://grails.org/doc/1.0.x/ref/Constraints/unique.html)中找到了解决方案,但所有其他Grails文档示例仅包含单个列的情况。不知道在8小时内不允许自我回答 – rainer198