1

I have a problem modeling a application for testing students. I want one Question and one Answer domain class. In each 'Question' I want to have fast access to all possible answers for this question and to the one correct answer. How to model that in Grails domain?

4

1 回答 1

2
  • 一个问题hasMany可能的答案。
  • 一个回答belongsTo一个问题。(可能会推迟,因为它没有被提及)
  • 在所有可能的答案中,只有一个isCorrect答案。

如果符合您的要求,请遵循上述模式,您将获得设计的域类。如果您发现任何困难,我可以很高兴地发布域类。:)

这是:(看到了你试图实现这一目标的另一个问题

class Question{
    //All possible answer contains the correct answer as well
    static hasMany = [answers: Answer]
}

class Answer{
    static belongsTo = [question: Question]

    //This determines whether the answer is the correct one for the 
    //related question.
    boolean isCorrect
}
于 2013-09-05T13:52:49.087 回答