grails 中由模糊的 def 递归引起的堆栈溢出
这是一个很奇怪的问题。
我在两个类(订阅和订阅)之间存在多对多关系。设想。问题是,当在每个类中使用“beforeDelete”删除其中一个时,我试图删除它们之间的关系。
ScenarioSubscription 是表示联结表的类。
这就是我的 beforeDelete def 在场景中的样子。
def beforeDelete = {
//Delete rows in junction table
def example = new ScenarioSubscription(scenarioId:id)
def scenSub = ScenarioSubscription.findAll(example)
scenSub*.delete(flush:true)
}
它适用于订阅类,但不适用于场景。相反,当调用 *.delete() 时,会递归调用“beforeDelete”def。我在调试时检查了变量,scenSub是ScenarioSubscription的列表。疯狂的?!
非常感谢您对正在发生的事情的任何想法。
this is a pretty strange issue.
I have a many-to-many relationship between two classes, Subscription & Scenario. Thing is I'm trying to delete the relation between them when either is deleted using "beforeDelete" in each of these classes.
ScenarioSubscription is the class representing the junction table.
This is what my beforeDelete def looks like in Scenario.
def beforeDelete = {
//Delete rows in junction table
def example = new ScenarioSubscription(scenarioId:id)
def scenSub = ScenarioSubscription.findAll(example)
scenSub*.delete(flush:true)
}
It works in the Subscription class but not in Scenario. Instead, when calling *.delete() the "beforeDelete" def is called recursively. I checked the variable when debugging and scenSub is a list of ScenarioSubscription. Crazy?!
Any idea of what is going on is very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,听起来您的
ScenarioSubscription
域对象有两个属性:Scenario
和Subscription
。当您尝试删除链接域对象时,它会尝试将删除级联到Scenario
,从而触发beforeDelete
闭包(并重复直到崩溃)我想您会需要定义 自定义级联映射为您的
ScenarioSubscription
属性,或者,您不能为此Scenario
域对象定义自定义映射,并摆脱您的beforeDelete
完全删除吗?即:
这个问题也可能有帮助
So, it sounds like your
ScenarioSubscription
domain object has two properties,Scenario
andSubscription
. When you try to delete the link domain object, it tries to cascade the delete down to theScenario
which fires thebeforeDelete
closure (and repeats till crash)I think you'll need to define a custom cascade mapping for your
ScenarioSubscription
properties, or, couldn't you define a custom mapping for thisScenario
domain object, and get rid of yourbeforeDelete
entirely?ie:
This question might be of help as well