当belongsTo指定多个类时,Grails的belongsTo级联删除?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我测试过,它遵循级联规则:如果删除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.