问题
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