Rails Polymorphic Naming Convention

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

Any suggestions or similar situations you've seen before?

+6
source share
1 answer

Try putting a name that automatically references the model name, so if the model is a comment, I would use commentable_type and commentable_id. For this particular case, I would use:

licensable_batch_type and licensable_batch_id

+3
source

Source: https://habr.com/ru/post/973725/


All Articles