当belongsTo指定多个类时,Grails的belongsTo级联删除?

发布于 2024-10-28 23:37:34 字数 304 浏览 8 评论 0原文

class Owner {
    static hasMany = Dog
}
class Sitter {
    static hasMany = Dog
}
class Dog {
    static belongsTo = [Owner, Sitter]
}

我的问题是:如果我创建一个 Dog 实例 D、一个 Owner 实例 O、一个 Sitter 实例 S,并将 D 与 O 和 S 关联起来,当 S 被删除时,O 会发生什么? O还会有D吗?既然是级联删除,那么S和D都会被删除,对吧? O什么时候会发生什么?还会有D吗?

class Owner {
    static hasMany = Dog
}
class Sitter {
    static hasMany = Dog
}
class Dog {
    static belongsTo = [Owner, Sitter]
}

My question is: If I create a Dog instance D, a Owner instance O, a Sitter instance S and associate D with both O and S, what happens to O when S gets deleted? Would O still have D? Since it's a cascade-delete, both S and D would get deleted, right? When what happens to O? Would it still have D?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

我一向站在原地 2024-11-04 23:37:34

我测试过,它遵循级联规则:如果删除Owner,Dog会被级联删除,但Sitter会保留。

这是合理的:保姆独立于所有者。仅仅因为 Sitter 与 Owner 有一些共同的属性,就应该将其与 Owner 一起删除,这是不合逻辑的。

I have tested it, it follows the cascade rule: if you delete Owner, Dog will be deleted by cascade, but Sitter will remain.

And it's reasonable: Sitter is independent with Owner. It's illogical that Sitter should be deleted along with Owner, just because he has some common properties with Owner.

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