I’m trying to create a simple one to one relationship, but leave it optional. When I attempt to save the “Face” object, I get the “must be unique” validation error. When the user adds a new “Face”, a “Nose” isn’t required. Later in the process, if the user does add a “Nose”, then it needs to be unique.
class Face {
Nose nose
static constraints = {
nose unique: true, nullable: true
}
}
class Nose {
}
Just as tim_yates mentioned, it does work on Grails 2.1.1. There was a configuration issue on my application.
To test this, I edited the FaceTests.groovy file with this simple test:
The result: