I need to relate a Comments model with two ids at the same time but can't figure out how. Here' my situation. I am building an on-line school grading system and need to be able let the teacher make a comment on a particular student in a particular course for a particular term (grading period).
class Course
has_many :course_terms
has_many :enrollments
end
class CourseTerm
belongs_to :course
end
class Student
has_many :enrollments
has_many :courses, :through => :enrollments
end
class Enrollment < ActiveRecord::Base
belongs_to :student
belongs_to :course
end
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end
I know it looks awfully complex but its pretty simple really. A course has many terms which a student can be enrolled in. I want to have comments for a CourseTerm + Student but I don't know if Polymorphic can handle multiple IDs in one comment. Can I do something like this:
class CourseTerm
has_many :comments, :as => :commentable, :source => [:student, :course_term]
end
Or do I have to forgo Polymorphics and go with a standard Comment table build with a CourseTerm.id and Student.id?