开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜