gpt4 book ai didi

Grails 域类 : unique constraint for multiple columns

转载 作者:行者123 更新时间:2023-12-02 19:36:33 24 4
gpt4 key购买 nike

假设一个简单的 Grails 域类:

class Account {
String countryId;

String userName;

String password;

static constraints = {
...???...
}
}

要求用户名对于特定的countryId是唯一的,因此两列上必须有唯一约束。如何在constraints定义中表达这一点?

最佳答案

userName(unique: ['countryId'])

您可以在数组中包含任意数量的其他属性,这些属性构成用户名的“唯一”约束中必须考虑的其他属性。

因此,例如,如果您想让 userNamecountryIdprovinceId 中唯一,则如下所示:

userName(unique: ['countryId', 'provinceId']

关于Grails 域类 : unique constraint for multiple columns,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7583380/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com