mongodb - 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 数据库。
解决方案
我已经切换到子文档模型,它现在正在工作。这是域模型代码。
class Author {
static mapWith = "mongo"
String name
List<Books> book
static embedded = ['book']
}
推荐阅读
- webrtc - 如何使用webrtcbin创建offer,只接收视频
- python - Python 解决方案 - 使用 Python 将 Microsoft BI 工作表导出到 Excel
- if-statement - 在 if 语句中使用范围
- php - 如何从 TempNam php 读取数据
- javascript - 如何使用nodejs获取父文件夹名称
- python-3.x - 为什么我们在 SLL 中将其原始节点属性默认设置为 None 时显式覆盖指向 None 的 next 指针?
- ruby - 运行“gem install bundler”时出现权限被拒绝错误
- meteor - 控制台日志有效,但返回在 Meteor 中无效
- reactjs - 如何使用反应组件创建滑块?
- javascript - 在 O(1) 中从数组中删除元素的方法