Grails belongsTo cascade on delete when belongsTo specifies multiple classes?

放肆的年华 提交于 2019-12-10 10:03:25

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5533305/grails-belongsto-cascade-on-delete-when-belongsto-specifies-multiple-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!