Reputation: 9314
In this Railscast Ryan Bates mentions that it's a good convention to use words that end in -tion, -ment, or -ship when naming a join model. What are the advantages of this convention?
For instance, what if I had a two models called "Albums" and "Songs" respectively where a song could appear on many albums and an album has many songs? What would be a good name for the join table needed for this? Tracklistingship? Tracklistings?
Upvotes: 2
Views: 127
Reputation: 160211
The convention is to name it something that makes sense.
Those relationships often end with those endings. The point is to follow a convention and be consistent, not necessarily that everything will fit neatly into the same three endings.
To me it sounds like Tracks
, AlbumTracks
, etc. If you wanted to follow his idea of making up a word, perhaps Trackation
or Trackination
(the process of putting tracks on an album), Albumship
(like "membership" but with album songs) etc.
Note also that hopefully you don't have models called Albums
and Songs
, rather Album
and Song
. IMO the clearest relationship is simply AlbumSongs
, because that's precisely what it is.
You could go a different route altogether and call them Mixes
, too.
Upvotes: 2
Reputation: 23493
One other advantage of using consistent naming conventions is that there is a pretty good chance you won't be the only one working on the code. By using a consistent naming convention, others who work on your code will have an easier time working on the code. You might also find it easier to maintain, in the sense that you might not touch the code for 6 months and one day come back to it. By having a consistent naming convention, you will be able to understand what you were doing without having to read through all your code.
Upvotes: 0