我有以下域类:
class StudentQuiz {
Date dateCreated
Date lastUpdated
Quiz quiz
float price
Student student
Date startTime
Date endTime
int score
List answers
static hasMany = [answers:Answer]
static constraints = {
answers nullable:true
}
}
但是当我使用以下代码保存此类的实例时:
studentInstance = (Student)User.findByEmailAndPassword(params.email, params.password.toString().encodeAsPassword())
if (studentInstance) {
StudentQuiz studentQuizInstance = new StudentQuiz(score:0, quiz:quizInstance,price:quizInstance.price,student:studentInstance,startTime:new Date())
if (!studentQuizInstance.save(flush:true)) {
studentInstance.errors.each {
println "===="+it+"-------"
}
}
我得到了这个:
grails.validation.ValidationErrors: 0 errors
没有其他错误解释。任何帮助都会非常感激。
答案 0 :(得分:0)
你正在检查错误的实例。它应该如下:
if (!studentQuizInstance.save(flush:true)) {
studentQuizInstance.errors.each {
println "===="+it+"-------"
}