Reputation: 7483
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?
Upvotes: 1
Views: 422
Reputation: 15126
One way to do it is to simply say that a Student has_many
assignments and has_many
courses. A Course also has_many
assignments. 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.
Upvotes: 1