I'm working on a hobby project and have an abstract Event
model with STI subclasses Meal
, Outing
, Medication
, etc. The Event
parent model has start_time
, end_time
, description
, etc.
I want to have nested resources for the various subclasses. For example, I want to be able to attach multiple instances of the Image
class to any Event
subclass. I want to be able to attach multiple instances of the Medicine
class to the Medication
entities, multiple instance of Location
to Outing
, etc.
My reason for considering polymorphism is to provide flexibility so that, conceivably, any of the different types of nested resources could be attached to any of the subclasses of Event.
This would allow somebody to attach a medicine of "Vitamin D Supplement" to a Meal
, for example.
My questions are:
- Should the nested resources be polymorphic?
- If I make them polymorphic, will all of the instances contain
Event
in the type table? - If so, should I just make them
has_many
relationships? - Is there any performance advantage to making them
has_many
vs. polymorphic?