Grails中具有许多关系的不同结果
我有两个类,即UserSurvey和SurveyResponseSet。UserSurvey有许多SurveyResponseSetGrails中具有许多关系的不同结果,grails,gorm,Grails,Gorm,我有两个类,即UserSurvey和SurveyResponseSet。UserSurvey有许多SurveyResponseSet class UserSurvey { Survey survey List responses = [] String surveyCompleted = '' . . . static hasMany = [ responses: SurveyResponseSet ]
class UserSurvey {
Survey survey
List responses = []
String surveyCompleted = ''
.
.
.
static hasMany = [
responses: SurveyResponseSet
]
static mapping = {
responses cascade: 'delete'
}
}
class SurveyResponseSet {
UserSurvey userSurvey
Integer sumWeight = 0
.
.
.
static constraints = {
sumWeight nullable:true, default: 0
}
}
要获取SurveyResponseSet列表,我在UserSurveyObject.responses之前就已经做过了,到目前为止,它工作正常。今天,它在遍历列表时开始抛出错误。
我正在使用Grails2.4.0。我试过干净,干净,但没有解决。
我进一步查看,发现UserSurveyObject.responses在列表中提供了一些空的额外结果。以下是控制台的结果:
UserSurvey uSurvey = UserSurvey.get(1437);
List<SurveyResponseSet> listFromSurvey = uSurvey.responses;
List<SurveyResponseSet> listUsingSurvey = SurveyResponseSet.findAllByUserSurvey(uSurvey);
println listFromSurvey;
println listUsingSurvey;
[null, nexant.SurveyResponseSet : 9788, nexant.SurveyResponseSet : 9789, nexant.SurveyResponseSet : 9793, nexant.SurveyResponseSet : 9794, nexant.SurveyResponseSet : 9795, null, nexant.SurveyResponseSet : 9874, nexant.SurveyResponseSet : 9875, nexant.SurveyResponseSet : 9879, nexant.SurveyResponseSet : 9880, nexant.SurveyResponseSet : 9881, nexant.SurveyResponseSet : 9882, null, nexant.SurveyResponseSet : 9884, nexant.SurveyResponseSet : 9885]
[nexant.SurveyResponseSet : 9795, nexant.SurveyResponseSet : 9794, nexant.SurveyResponseSet : 9793, nexant.SurveyResponseSet : 9789, nexant.SurveyResponseSet : 9788, nexant.SurveyResponseSet : 9885, nexant.SurveyResponseSet : 9884, nexant.SurveyResponseSet : 9882, nexant.SurveyResponseSet : 9881, nexant.SurveyResponseSet : 9880, nexant.SurveyResponseSet : 9879, nexant.SurveyResponseSet : 9875, nexant.SurveyResponseSet : 9874]
UserSurvey uSurvey=UserSurvey.get(1437);
List listFromSurvey=uSurvey.responses;
ListListUsingSurvey=SurveyResponseSet.findAllByUserSurvey(通常情况下);
从调查中打印;
打印列表使用调查;
[null,nexant.SurveyResponseet:9788,nexant.SurveyResponseet:9789,nexant.SurveyResponseet:9793,nexant.SurveyResponseet:9794,nexant.SurveyResponseet:9795,null,nexant.SurveyResponseet:9874,nexant.SurveyResponseet:9875,nexant.SurveyResponseet:9879,nexant.SurveyResponseet:9880,nexant.SurveyResponseet:81,nexant.SurveyResponseSet:9882,空,nexant.SurveyResponseSet:9884,nexant.SurveyResponseSet:9885]
[nexant.SurveyResponseSet:9795,nexant.SurveyResponseSet:9794,nexant.SurveyResponseSet:9793,nexant.SurveyResponseSet:9789,nexant.SurveyResponseSet:9788,nexant.SurveyResponseSet:9885,nexant.SurveyResponseSet:9884,nexant.SurveyResponseet:9882,nexant.SurveyResponseet:9881,nexant.SurveyResponseet:9880,nexant.SurveyResponseonseSet:9879,nexant.SurveyResponseSet:9875,nexant.SurveyResponseSet:9874]
我不明白它从何处获取了三个额外的空对象。关于空对象,您可以尝试:
class SurveyResponseSet {
UserSurvey userSurvey
Integer sumWeight = 0
.
.
.
static mapping = {
userSurvey ignoreNotFound : true
}
static constraints = {
sumWeight nullable:true, default: 0
}
}
查看是否从列表中删除空元素什么数据库&它是否支持关系(例如MySQL MyISAM不支持)?MySQL InnoDB。它在早期和其他域中都运行良好。如何在UserSurvey中添加SurveyResponseSet?请尝试使用
集合
而不是列表
来获取响应。它似乎正在处理列表索引improperly@heikkim我认为说MySQL MyISAM不支持关系是不准确的。它仍然是一个关系数据库。我认为它有一些限制,比如对关系的限制,但它肯定支持关系,仍然得到同样的结果。