Grails(GORM) - 多个多对多和级联删除

时间:2014-07-31 14:53:22

标签: grails many-to-many gorm

我们说我有3个域类:

class Book {
    static belongsTo = [Author,User]
    static hasMany = [authors:Author,usersWhomReadThisBook:User]
    String title
}
class Author {
    static hasMany = [books:Book]
    String name
}
class User {
    static hasMany = [booksRead:Book]
    String name
}

belongsTo定义了级联关系,因此删除父级将删除属于它的所有对象。

问题是:当我删除用户时,它是否会级联并删除用户已阅读的图书?即使它仍然属于现有的作者?或者它只从连接表中删除?

此用例的文档不清楚。

1 个答案:

答案 0 :(得分:0)

你的问题是:
When I delete a User does it cascade up and delete the Books the user have read? Even if it still belongs to an existing Author? Or does it only delete from the join table?

答案是:对于很多人来说,没有删除不会被级联,如果我们删除该用户,只会将其删除,因为这些书籍与其他类作者相关联。