Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails polymorphic naming convention

I'm trying to figure out what to name a polymorphic association and not coming up with good options. The class that will contain the polymorphic association is called LicenseBatch, and if it weren't polymorphic, the foreign key would just be owner_id. It seems that the go-to polymorphic name would be ownerable, but what if I have another class that is ownable? I'd like this to be more specific, but things like batch_ownerable sound awkward.

Any suggestions or similar situations you have seen before?

like image 226
Phil Avatar asked Aug 12 '14 21:08

Phil


1 Answers

Try to put a name that automatically refers to the model name, so if the model is Comment I would use commentable_type and commentable_id. For this specific case I would use:

licensable_batch_type and licensable_batch_id

like image 163
apeniche Avatar answered Nov 15 '22 10:11

apeniche