grails 中由模糊的 def 递归引起的堆栈溢出

发布于 2024-12-08 21:56:40 字数 562 浏览 0 评论 0原文

这是一个很奇怪的问题。

我在两个类(订阅和订阅)之间存在多对多关系。设想。问题是,当在每个类中使用“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏日落 2024-12-15 21:56:41

因此,听起来您的 ScenarioSubscription 域对象有两个属性:ScenarioSubscription。当您尝试删除链接域对象时,它会尝试将删除级联到 Scenario ,从而触发 beforeDelete 闭包(并重复直到崩溃)

我想您会需要定义 自定义级联映射为您的 ScenarioSubscription 属性,或者,您不能为此 Scenario 域对象定义自定义映射,并摆脱您的beforeDelete 完全删除吗?

即:

static mapping = {
  subscriptions cascade:"all-delete-orphan"
}

这个问题也可能有帮助

So, it sounds like your ScenarioSubscription domain object has two properties, Scenario and Subscription. When you try to delete the link domain object, it tries to cascade the delete down to the Scenario which fires the beforeDelete 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 this Scenario domain object, and get rid of your beforeDelete entirely?

ie:

static mapping = {
  subscriptions cascade:"all-delete-orphan"
}

This question might be of help as well

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文