This is mainly a theoritical question, but just wanted to make sure that i’m doing it correctly. Consider a Ruby Rails project where there are two models, one being User and the other being Alliance.
A user can only have one alliance.
An alliance can have many users.
That is very much simply a :has_many, :belongs_to relationship.
However, i feel that using an intermediate model is a better way to do it. That would be a :has_many :through :users_alliances, where users_alliances would be an intermediate model.
What do you think is the best way to do that ?
Don’t use habtm, it doesn’t make the join into a fully fledged model, which is what you need. Use has_many :through on the alliance side and has_one :through on the user side.
Personally i prefer the class name AllianceMembership to UserAlliance but you could use either. UsersAlliances is ugly though imo. (another advantage of has_many/one :through is that you can call the join table/class whatever you want).
This gives you the option to easily change to users having many alliances later on if you want.