It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media
This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.
Commenting here just to see if anyone knows: What would the db migrations look like for this scenario?
has_many :through
has always hurt my brain a little, so I'm having trouble writing the migration by hand. I've been looking at this StackOverflow, but so far I can't get it to work 😢