gorm - How to update an instance with field unique that has not changed in Grails? -
i have problem when trying update instance has field constraint: unique, 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") nombre has not changed */
def sectorempresarialinstance = sectorempresarial.findbycodigo(1) sectorempresarialinstance.properties = params sectorempresarialinstance.save(flush:true) // here present error because nombre has constraint: unique.
Comments
Post a Comment