In the below code validate() is returning false but I am not seeing any errors. As the validate method is failing the data is not getting persisted to the database.
if (!stockInstance.validate() && stockInstance.save(flush: true))
//redirect(action: "show", id: saleInstance.id)
} else {
println 'stock instance has errors'
stockInstance.errors.each {
println it
}
render(view: "edit", model: [saleInstance: saleInstance])
}
This is printing
stock instance has errors
org.springframework.validation.BeanPropertyBindingResult: 0 errors
So where else could the error be.
Sorry was not watching the data properly, It was getting persisted correctly.
You have
!stockInstance.validate()but it should bestockInstance.validate().!stockInstance.validate() && stockInstance.save(flush: true)can never be true sincesave()callsvalidate()so it becomes!stockInstance.validate() && stockInstance.validate()It’s not persisting since the
save()call doesn’t happen since thevalidate()call returnstrue(so the 1st check is false).Since
save()callsvalidate()I’m not sure why you have the extra call there though.