Take the 2-minute tour ×

very noobish question; only getting deeper into ROR recently but have been a dev for years. This is more a conceptual question more than anything.

I'm working on an app where there might be episodes - ie videos of a show model. All good there. However the episodes might be 1 of 4 different video providers -- so I was thinking of an Embed or VideoProvider model where I'd have the provider (ie 'youtube') and 'code' with the embed and be able to string replace items.

The episode model will have an embed_id pointing to which one of these Embeds were chosen and a videoparam (or something) field with the replaceable video id / code.

The thing is, following it this way allows me to have the embed_id in the episode and the Embed can have many episodes -- which means that the Episode actually belongs to the Embed to get the foreign key that way. Maybe I'm being anal but that just doesn't FEEL right -- the embed belongs to episode in my mind, but setting up that way won't work.

I mean imagine a user - and there's a Gender model (I know, dumb for m/f but just as example). If the user needed to choose from m/f, the user wouldn't belong to gender; gender would belong to user, but again, the foreign key is set up wrong then.

SO my question is: the idea of 'belongs to' -- should I not be so rigid as to what it means OR should I use a join table in these cases (which seems overblown). ie if I have an Episode that is pulling in the Embed by holding it's embed_id, then who cares...?

share|improve this question
i'm not sure if i get everything right? what exactly would be wrong with: class Show has_many :episodes end class Episode belongs_to :show has_many :embeds end class Embed belongs_to :episode end ..forein_key always on the model that has the belongs_to sorry, here as gist so not everythings in one line: gist.github.com/anonymous/6380082 –  trueunlessfalse Aug 29 '13 at 16:06
Can you post your models? –  settheline Aug 29 '13 at 16:13
Think of the embed as a template - ie it's a blank template for youtube, vimeo, viddler, etc - the episode has title / description and the video id - one would choose which embed to use for each episode, so the Embed couldn't have the foreign id (ie belongs_to episode); instead the episode would have the id of which embed should be utilized (ie episode belongs_to embed, embed has_many episodes) -- it WORKS this way but I don't know if conceptually thats' the right way to do it. –  Garry Schafer Aug 29 '13 at 21:15
In theory - and maybe there's TOTALLY a better way here - is there something like templates I could use? I mean say if in the episode I only have a pulldown of 'youtube/viddler/vimeo' and then a switch in the view for outputting the proper embed... but the reason I thought there could be an embed model is as other third party providers come up they could be added. –  Garry Schafer Aug 29 '13 at 21:18
Perhaps commenting on my own thing too much - but lets say there's a 'gender' model that you want a user to use -- yes simple enough to just have m/f but if a user has_one gender then the gender has belongs_to user, then the gender would have the foreign key to the user - not good. Instead you'd have user belongs_to gender and genders has_many users - which works but doesn't make sense. SO would one use a GenderUser join for something so simple? –  Garry Schafer Aug 29 '13 at 21:26
add comment

Your Answer



Browse other questions tagged or ask your own question.