让我们直接解决问题(对于 Grails 1.1.1,它应该适用于之前的问题)
我有 2 个域,即:像这样的用户和详细信息:
Class User {
String userName ;
..... // another fields
static hasMany = [details:Detail];
}
Class Detail{
String detailName ;
... // another fields
static belongsTo = [user:User];
}
现在,如果我这样做了:
def user = User.get(1);
Detail.findAllByUser(user);
为什么会产生错误?
但是如果我对细节进行修改
Class Detail{
String detailName ;
... // another fields
User user;
static belongsTo = [user:User];
}
(通过添加用户)它将像正常一样工作......
使用 belongsTo 有什么效果吗?或者我在这里做了错误的概念?