table "users" [Stores user information]
id, username, password,email
table "exams" [Stores exam information]
id, name, description
table "questions" [stores question information]
id, question, opt1, opt2, opt3,opt4, correct
table "exam_questions" [stores selection of questions for a particular
exam or test]
id, exam_id, question_id
table "user_answers" [stores the user response to the questions in exam]
id, user_id,exam_id,question_id,userans, created_at
Associations in my models:
has_many :questions, :through=>:exam_questions
has_many :exams, :through=>:exam_questions
Now what I need is:
1. To extract the exam and question details by running a query in
ExamQuestion table. Is this possible?
something like: @detail=ExamQuestion.find(:all) and then looping also
displaying the question and exam detail. I don't want to use find_by_sql
2. Also to extract form UserAnswer table and display the exam detail,
question detail and user answer with a single hit in database.
In general terms, I want to use the features of Active Record
associations to run a query to extract as much informaton as possible
from multiple tables.
This is to avoid multiple queries.