在grails 中有一个关系和删除
我应该如何删除grails中hasOne关系中的子对象 例如:
class Face {
static hasOne = [nose: Nose]
}
class Nose {
Face face
static belongsTo= Face
}
我尝试通过两种方式删除子对象,
1. face.nose.delete()
2. nose.delete()
但我总是得到相同的异常:通过级联以两种方式重新保存已删除的对象。还有一件事,我是否有针对 hasOne 的动态方法(例如 hasMany 的 addTo 和 removeFrom)? 有什么帮助吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以尝试
如果你只删除nose,那么属性face.nose仍然被设置。稍后调用face.save()将重新保存鼻子。
如果您仅设置face.nose = null(不保存),则更改不会保存到数据库中。稍后对数据库进行查询以获取人脸时,将为您提供一张带有鼻子设置的人脸,并且 save() 将重新保存它。
You could try
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.
尝试按如下方式创建您的课程:
然后删除尝试:
Try making your class as follows:
Then to delete try:
试试这个
try this