Before I proceed with my answer I want to caveat that with Grails 1.2.x (possibly 1.3.x as well) compound unique constraints are broken if any of the values can be null. If you cannot live without unique behavior you can use a custom validation to do the trick. See: https://cvs.codehaus.org/browse/GRAILS-5101
The proper way to accomplish having your Metric domain class be unique within name, person, and corporation.
class Metric {
String name
float value
Person person
Corporation corporation
static belongsTo = [person: Person, corporation: Corporation]
static indexes = {
name()
}
static constraints = {
name(unique:['person', 'corporation'])
person(unique:['name', 'corporation'])
corporation(unique:['name', 'person'])
}
}
You will need to call out person and corporation as members of your model. You could even drop the static belongsTo if you do not care about cascading delete behavior.
In the above example, name must be unique in person and corporation; person must be unique in name and corporation, and finally corporation must be unique in name and person.