Rails newbie here struggling to understand ActiveRecord.
I have 6 tables:
- Class -> has many subjects
- Subject -> has many projects
- Project -> has many tasks
- Task -> has many scores
- Score (records a score for each task and a time stamp)
- Student -> has many scores
A student may redo a task many times in order to get a better score,
but I am (via the timestamp) recording multiple scores per task for
each student to keep track of progress over time. For example,
some score records might look like:
student_id, task_id, score, recorded_on
1 , 37 , C , 07-01-2007
2 , 28, , D , 07-01-2007
1 , 37 , B , 07-25-2007
Notice how student #1 has two grades for task #37 (over time, this
could have 4 or 5 grades for that task – and there are 150 tasks!).
I’ve got two problems:
I need to be able to see the most recent scores for
a student on all 150 tasks (e.g. I’d want the 07-25-2007 score for
#1 rather than the 07-01-2007 older score).
In order to make the webpage, I need to be able to link task_id back
to the Project and then back to Subject and then back to Class and
also back to Student so that I can get for example, the student name
rather than just his “primary key number” or the Project description
or the Class name, etc.
I can almost get the first one with something like this:
@m = Score.maximum :recorded_on, :group => “task_id”, :conditions =>
[“student_id = ?”, params[:id]]
which gives [element_id, :recorded_on] combinations with the most
recent “recorded_on” value for that task… How can I
include the score, timestamp and even student_id field for that
most recent record?
How can I then link all the other tables back in to get access to all
Thanks in advance,