You would use those, and some more of Rails' magic :)
class Course
has_many :participants, class_name: 'User'
has_many :subjects, conditions: ['type = ?', 'Subject']
has_many :locations, conditions: ['type = ?', 'Location']
has_many :events, as: :eventable
end
class User
has_many :subjects, conditions: ['type = ?', 'Subject']
has_many :locations, conditions: ['type = ?', 'Location']
has_many :events, as: :eventable
belongs_to :event, foreign_key: :teacher_id
end
class Resource
has_many :contacts, class_name: 'User'
has_many :events, as: :eventable
end
class Event
belongs_to :eventable, polymorphic: true
has_many :teachers, class_name: 'User'
has_many :subjects, conditions: ['type = ?', 'Subject']
has_many :locations, conditions: ['type = ?', 'Location']
has_many :media, conditions: ['type = ?', 'Medium']
end
I think this covers all of your use cases.
note: You should probably rename your model from Media
to Medium
since Rails works better with singularized model names and you might run into some issues if you don't.