Grails领域类:多列的唯一约束

假设一个简单的Grails域类:

class Account { String countryId; String userName; String password; static constraints = { ...???... } } 

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

 userName(unique: ['countryId']) 

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

所以,举例来说,如果你想在countryIdprovinceId使用countryId唯一的,它看起来像这样:

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