Grails通过父域一对多更新

Grails通过父域一对多更新,grails,gorm,Grails,Gorm,我有类似于以下场景的域对象 Author{ Long id static hasMany = [ autthorBook: AuthorBook ] } Book{ Long id } AuthorBook{ Long id Book book Author author static belongsTo = Author static mapping = { book column: 'book_id'

我有类似于以下场景的域对象

Author{
    Long id
    static hasMany = [
        autthorBook: AuthorBook
    ]
}

Book{
    Long id
}

AuthorBook{
   Long id
   Book book
   Author author
   static belongsTo = Author

   static mapping = {
    book column: 'book_id'
    author column: 'authod_id'
    version false
   }
}
在更新过程中,我得到了作者id和一组图书id。如何在不手动检查AuthorBook是否存在或已删除AuthorBook的情况下更新Author。我需要一种方法,在结束时

Author.save()

执行时(作者将有一个没有id的新AuthorBook列表),以更新AuthorBook表,删除不再存在的AuthorBook条目,并在需要时添加新条目,而无需手动检查每个现有条目的循环。

无关-无需为域类添加
长id
属性。Grails已经在编译过程中为您完成了这项工作。您是否考虑过在Author和Book之间使用多对多?基本上就是你在做什么,除了戈姆能帮你做一些工作。换句话说,这会简化事情。我已经考虑过了。但根据我的要求,结构必须与此类似。因此,我不能在author和bookUnrelated之间建立多对多的关系-不要麻烦向域类添加
Long id
属性。Grails已经在编译过程中为您完成了这项工作。您是否考虑过在Author和Book之间使用多对多?基本上就是你在做什么,除了戈姆能帮你做一些工作。换句话说,这会简化事情。我已经考虑过了。但根据我的要求,结构必须与此类似。所以我不能在作者和书之间建立多对多的关系