4

複数の列に対して名前付き一意制約を作成するにはどうすればよいですか?

私は3つのクラスを持っています:

class Descriptor {
    // some columns
}

class Protein {
    // some columns
}

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

GORM は、環境ごとに異なる自動生成された名前でインデックスを作成します。その名前を指定するにはどうすればよいですか?

4

2 に答える 2

1

次のようにしてみてください:

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

複数列のインデックスを使用する必要がある場合は、すべてのプロパティに同じインデックス名を指定できます。

于 2012-08-17T16:50:58.070 に答える
0
String field1
String field2
Integer field3
SomeObject object

  static constraints = {
        object unique: ['field1','field2', 'field3']
    }
于 2013-09-26T11:00:15.827 に答える