Grails: How can I create a named unique constraint for multiple columns?

How can I create a named unique constraint for multiple columns?

I have three classes:

class Descriptor { // some columns } class Protein { // some columns } class DescriptorValue { // some columns static belongsTo = [protein: Protein, descriptor: Descriptor] static constraints = { protein(unique:['descriptor']) } } 

GORM creates an index with an automatically generated name that is different for different environments. How can I indicate his name?

+4
source share
2 answers

Try to do it like:

 static mapping = { protein unique:['descriptor'], index: 'protein_idx' //or whatever name you like } 

If you need to use indexes with multiple columns, you can specify the same index name for each property.

+1
source
 String field1 String field2 Integer field3 SomeObject object static constraints = { object unique: ['field1','field2', 'field3'] } 
0
source

All Articles