Grails 反向级联删除,不带 hasMany 或 BelongsTo
我有两个域类。
class UsersAddThese {
String someData
}
是否
class TheseAreConstantlyGenerated {
UsersAddThese theProblem
}
有某种方法可以删除 UsersAddThese
并自动删除所有 TheseAreConstantlyGenerate
或者我应该将逻辑添加到 findAllByTheProblem
然后迭代并删除。 (我希望它可以自动完成,这样我就可以添加引用 UsersAddThese
的新生成类,而不是更改删除控制器。)
或者,是否有某种方法可以告诉 GORM,“如果有什么事情否则取决于我要删除的内容,从而导致错误 util.JDBCExceptionReporter - 无法删除或更新父行:外键约束失败
,也将其删除 - 递归。”
I have two domain-classes.
class UsersAddThese {
String someData
}
and
class TheseAreConstantlyGenerated {
UsersAddThese theProblem
}
Is there some way to delete a UsersAddThese
and automatically delete all the TheseAreConstantlyGenerated
or should I just add in logic to findAllByTheProblem
and then iterate and delete. (I would prefer if it could be done automatically so I can add new Generated classes that refer to UsersAddThese
and not change the delete controller.)
Alternatively, is there some way to just tell GORM, "If something else depends on what I am deleting so as to cause ERROR util.JDBCExceptionReporter - Cannot delete or update a parent row: a foreign key constraint fails
, delete that too - recursively."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,看起来引用完整性的全部要点是不要做你在问题的第二部分中试图做的事情。但是,您可以将此闭包添加到您的 UsersAddThese 域类中:
这应该可以解决问题。
Well, it seems like the whole point of referential integrity is to NOT do what you're trying to do in the 2nd part of your question. However, you can add this closure to your UsersAddThese domain class:
That should do the trick.