Grails domain class: unique constraint for multiple columns

前端 未结 1 1150
谎友^
谎友^ 2020-12-14 05:54

Suppose a simple Grails domain class:

class Account {
    String countryId;

    String userName;

    String password;

    static constraints = {
        .         


        
相关标签:
1条回答
  • 2020-12-14 06:29
    userName(unique: ['countryId'])
    

    You can include as many other properties in the array that make up the other properties that must be considered in the "unique" constraint on the username.

    So, for example if you wanted to make userName unique within a countryId and provinceId it would look like this:

    userName(unique: ['countryId', 'provinceId']
    
    0 讨论(0)
提交回复
热议问题