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']
}
精彩评论