How should I delete the child object in a hasOne relationship in grails for e.g.:
class Face {
static hasOne = [nose: Nose]
}
class Nose {
Face face
static belongsTo= Face
}
I tried deleting the child object by two ways
1. face.nose.delete()
2. nose.delete()
I always get the same exception Deleted object resaved by cascade in both the ways. And one more do I have any dynamic methods (like addTo and removeFrom for hasMany) for hasOne? Any help?
You could try
face.nose = null
face.save()
nose.delete()
If you only delete nose then the property face.nose is still set. A later call of face.save() would resave the nose.
If you only set face.nose = null (without saving) then the change isn't saved to the database. A later query to the database to get a Face would give you a Face with the nose set and a save() would resave it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With