首页 > 解决方案 > Grails GORM有很多与MongoDB不一致的关联,当尝试获取子记录时,有时会获取记录,有时不获取

问题描述

下面是与Author具有一对多关联的域类Book。在尝试获取 Author 时,有时会获取Book域对象的关联集合,有时会返回 null。关于为什么不一致的任何想法?

class Author { static mapWith = "mongo" String name static hasMany = [books: Book] }

_author.gson

model { Author author } json g.render(author]) { books g.render(author.books) }

环境细节:

grailsVersion=3.3.5 gormVersion=6.1.8.RELEASE

我们正在使用 GORM 多租户并使用 MongoDB 数据库。

标签: mongodbhibernategrailsgrails-orm

解决方案


我已经切换到子文档模型,它现在正在工作。这是域模型代码。

class Author {
    static mapWith = "mongo"
    String name
    List<Books> book
    static embedded = ['book'] 
}

推荐阅读