grails文档中的这一行是多余的吗?

grails文档中的这一行是多余的吗?,grails,gorm,Grails,Gorm,首先请到这里来 如果滚动几行,您将看到该行 最后,最好在一对一关系的一侧添加唯一约束: 代码是 class Face { static hasOne = [nose:Nose] static constraints = { nose unique: true } } 我取出了以下两个域定义的变更日志,但没有唯一的:true class Nose { String name Cat cat static constraints

首先请到这里来

如果滚动几行,您将看到该行

最后,最好在一对一关系的一侧添加唯一约束:

代码是

class Face {
    static hasOne = [nose:Nose]
    static constraints = {
        nose unique: true
    }
}
我取出了以下两个域定义的变更日志,但没有唯一的:true

class Nose {

    String name
    Cat cat

    static constraints = {
    }
}

class Cat {

    String name
    static hasOne = [nose: Nose]


    static constraints = {
    }
}
更改日志显示已添加唯一的

    <changeSet author="S (generated)" id="1452758231706-5">
        <createIndex indexName="cat_id_unique_1452758231629" tableName="nose" unique="true">
            <column name="cat_id"/>
        </createIndex>
    </changeSet>


因此,虽然文档中很少有多余的语句并不是什么大问题,但我想确保unique:true确实不是必需的。指定hasOne并有一个back引用就足以使关系真正成为一对一。对吗?谢谢

使用unique,您也可以有空值,但不能使用hasOne和back引用。@Sandeepoonia我测试过,即使使用unique约束,也不允许有空值。