I’m a little rusty on my ActiveRecord, so forgive me if the answer is somehow obvious.
I have three model objects in a rails project: Student, Assignment, and Course. As you might imagine, a Course has_many assignments. Now I want to be able to assign to a Student an arbitrary number of Courses and individual Assignments.
I’ve tried to use a polymorphic association based on the notion of ‘assignable’, but can’t get it to work properly.
What’s the most natural way to model these relationships in rails?
One way to do it is to simply say that a Student
has_manyassignments andhas_manycourses. A Course alsohas_manyassignments. Of course I don’t know what you’re trying to achieve in your application, but it seems that courses and assignments are completely different entities, so I’m not sure why you’d like a polymorphic association.