繁体   English   中英

Grails多对多双向

[英]Grails Many-to-Many Bidirectional

我在GORM中创建多对多双向关系时遇到问题,而我发现的解决方案并不是我真正想做的。

我目前建立的关系允许作者拥有多本书,但不能反过来(所有权在作者方面)。 这是我目前拥有的代码。

class Author {

    String name

    static hasMany = [books:Book]

        static constraints = {
           name(nullable:false)
        }
        String toString() {
           name
        }
}

class Book {

   String name
   String type
   Integer year
   Author authors

   static belongsTo = [authors:Author]
   static hasMany = [authors:Author]

   static constraints = {
       name(nullable:false)
       type(nullable:false)
       year(nullable:true)
       authors(nullable:false)
   }

   String toString() {
      name
   }
}

我希望这种关系使得在编辑一本书时,除了在编辑一个作者时由同一位作者拥有多本书之外,我还可以选择多位作者。

Grails支持许多种房地产,并且您的代码必须能够正常运行...但是有一个小问题...脚手架不支持它,因此您必须编写自己的代码来根据需要处理关系!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM