【发布时间】:2016-01-11 16:35:34
【问题描述】:
我有 3 节课:
class Author {
static hasMany = [books: Book]
static belongsTo = [company: Company]
String name
}
class Book {
static mapping = {
collection "documents"
id generator: 'assigned',index: true, indexAttributes:[background:true, unique:true, dropDups:true]
}
String id
String name
}
class Company {
static mapping = {
collection "documents"
id generator: 'assigned',index: true, indexAttributes:[background:true, unique:true, dropDups:true]
}
String id
String name
}
我想用
Author author = Author.getByCompanyAndBook(1,1);
但是当运行这个 Grails 时,它会从数据库中检索所有 Book 对象。
我只需要这些书籍作为作者的标识符,我不会使用这些对象。
有没有办法让 Grails 不从数据库中获取书籍和公司?
我尝试使用:
static mapping = {
books lazy: true
}
但仍然加载了所有书籍和公司。
编辑:
我使用 mongo db 作为我的数据库。
【问题讨论】:
-
你使用的是什么 grails 版本?