0

我有以下域类:

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

没有其他错误解释。任何帮助将非常感激。

4

1 回答 1

0

您正在检查错误的实例。应该如下:

if (!studentQuizInstance.save(flush:true)) {                    
    studentQuizInstance.errors.each {
    println "===="+it+"-------"
}
于 2013-01-10T12:49:03.770 回答