开发者

How to set unique constraint on two foreign fields in Grails?

开发者 https://www.devze.com 2023-03-17 14:53 出处:网络
Suppose I have a class with following definition: 开发者_如何转开发class ClassA { static belongsTo = [ownerB:ClassB, ownerC:ClassC]

Suppose I have a class with following definition:

开发者_如何转开发class ClassA { 
    static belongsTo = [ownerB:ClassB, ownerC:ClassC]
}

How I can enforce an unique constraint on above "belongsTo" relationship?


Using the Map form of belongsTo creates fields with those names, so you can do it with

static constraints = {
   ownerB unique: 'ownerC'
}


Refer http://grails.1312388.n4.nabble.com/Creating-a-foreign-key-constraint-td1352053.html


String field1
String field2
Integer field3
SomeObject object

  static constraints = {
        object unique: ['field1','field2', 'field3']
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消