Saioa
Feb 4th, 2011, 03:38 AM
Hello,
In my domain class I've created the beforeInsert method and I'm checking the value of a property there. In some cases I don't want the object to be persisted to the db, so I'm returning false. I've read that this is supposed to work but it doesn't, the object is still being saved...
This is my method
def beforeInsert = {
if (accion=="update")
{
QuartzJob tareaBorrado = new QuartzJob(idEmpresa:idEmpresa,idSede:idSede,url:ur l,accion:'delete')
tareaBorrado.save()
QuartzJob tareaCrawl = new QuartzJob(idEmpresa:idEmpresa,idSede:idSede,url:ur lNueva,accion:'crawl')
tareaCrawl.save()
return false
}
else if (accion=="schedule")
{
Calendar calendario = new GregorianCalendar()
calendario.set(calendario.get(Calendar.YEAR),calen dario.get(Calendar.MONTH),calendario.get(Calendar. DATE),grailsApplication.config.crawler.reindexacio n.hora.toInteger(),grailsApplication.config.crawle r.reindexacion.minutos.toInteger())
fechaSchedule = calendario.getTime()
dateCreated = calendario.getTime()
}
}
What I want to achieve is to change an insert wich has the property accion="update" to two inserts, one with accion="delete" and another one with accion="crawl". The rows with accion="delete" and accion="crawl" are inserted without problem, but the row with accion="update" is also persisted.
Any suggestion?
Thanks
In my domain class I've created the beforeInsert method and I'm checking the value of a property there. In some cases I don't want the object to be persisted to the db, so I'm returning false. I've read that this is supposed to work but it doesn't, the object is still being saved...
This is my method
def beforeInsert = {
if (accion=="update")
{
QuartzJob tareaBorrado = new QuartzJob(idEmpresa:idEmpresa,idSede:idSede,url:ur l,accion:'delete')
tareaBorrado.save()
QuartzJob tareaCrawl = new QuartzJob(idEmpresa:idEmpresa,idSede:idSede,url:ur lNueva,accion:'crawl')
tareaCrawl.save()
return false
}
else if (accion=="schedule")
{
Calendar calendario = new GregorianCalendar()
calendario.set(calendario.get(Calendar.YEAR),calen dario.get(Calendar.MONTH),calendario.get(Calendar. DATE),grailsApplication.config.crawler.reindexacio n.hora.toInteger(),grailsApplication.config.crawle r.reindexacion.minutos.toInteger())
fechaSchedule = calendario.getTime()
dateCreated = calendario.getTime()
}
}
What I want to achieve is to change an insert wich has the property accion="update" to two inserts, one with accion="delete" and another one with accion="crawl". The rows with accion="delete" and accion="crawl" are inserted without problem, but the row with accion="update" is also persisted.
Any suggestion?
Thanks