I have a problem when trying to update an instance that has a field with constraint: unique, but has not been modified.
https://grails.github.io/grails-doc/latest/ref/Constraints/unique.html
class SectorEmpresarial{
Long codigo
String nombre
static constraints = {
nombre nullable: false, size: 0..50, unique: true
}
}
Example:
Instance Created
def sectorEmpresarialInstance = new SectorEmpresarial(codigo:1,nombre:"MY_NAME") sectorEmpresarialInstance.save(flush:true)
Editing Instance (ERROR here)
/* params=(codigo:2, nombre:"MY_NAME") look that nombre has not changed */
def sectorEmpresarialInstance = SectorEmpresarial.findByCodigo(1) sectorEmpresarialInstance.properties = params sectorEmpresarialInstance.save(flush:true) // Here present error because nombre has constraint: unique.