0

I am designing a grails app and many many-to-many relations have me stumped. This is what I have so far...

Domain classes

  • Students
  • Tests
  • Questions

Here tests and questions will have m2m relationship. Which might be represented by a mapping class, please correct me if I am wrong.

 TestConfig 

This class can have many questions and many tests.

But I am still confused about how my data model can be designed when a student takes tests and attempts question. A class that may be called Attempts which will have answers(possibly wrong) given by the student, should it belong to students or tests or both?

I want to design an "Attempts" class so that when I look at an instance of it I can know what test it belong to as well as which student took it.

My current classes look like following

class Questions {
    String question
    String questionType
    int points
    String tags
    String option_1
    String option_2
    String option_3
    String option_4
    boolean isOption_1_Correct
    boolean isOption_2_Correct
    boolean isOption_4_Correct
    boolean isOption_3_Correct
}

class Students {
    String firstName
    String lastName
    String email
    String password
}

class Tests {
    String name
    String tags
    String description
    int duration
    String instruction
}

------EDIT---------

I think I have found something useful here http://www.databaseanswers.org/data_models/online_exams/index.htm

chrislovecnm
  • 2,549
  • 3
  • 20
  • 36
Sap
  • 5,197
  • 8
  • 59
  • 101
  • 1
    Try reading. A good start is: http://stackoverflow.com/questions/574001/what-books-do-you-suggest-for-understanding-object-oriented-programming-design-d – AA. Aug 27 '12 at 01:33

1 Answers1

0

From what I understand a Student has many Tests and Tests have many Questions

Here are the docs

http://grails.org/doc/2.1.0/guide/GORM.html#manyToMany

class Student {
    // a list named tests which contains Test object
    static hasMany = [tests:Test]
    String name
}

class Test {
    static belongsTo = Student

    // a list named students which contains Student objects
    // a list named questions which contains Quention objects
    static hasMany = [students:Student,questions:Question]
    String title
}

class Question {
    static belongsTo = Test
    static hasMany = [tests: Tests]
    String data
}
chrislovecnm
  • 2,549
  • 3
  • 20
  • 36