title: Enforcing association uniqueness in ActiveRecord
body: <p>There are three sets of entities: <code>Players</code>, <code>Teams</code> and <code>Games</code>. Team may consist from one or two <code>Players</code> and are formed voluntary for each particular <code>Game</code>, i.e.
  players A,B,C,D can form 11 <code>Teams</code> because <code>Team</code> AB is the same as <code>Team</code> BA. 
  That being said <code>Teams</code> may contain only unique set of players - BA is a duplication of AB.</p>
  
  <p>The most obvious way to form the  <code>Teams</code> and <code>Games</code> relationship is as many to many, but is this a way to go? The real question is  how  to model those restrictions in robust and scalable way, so they can handle, let's say, a team not of only 1-2 players but also a team of 1-20 players without (much) augmentation?</p>
  
  <p>Here is an  abstract interface I'm thinking of -</p>
  
  <pre><code>Team.find_or_create_by(player_ids: [p1.id, p2.id]) # find p1 and p2 team
  Team.find_by(player_id: p1) # find all teams that p1 has participated in
  </code></pre>
  
  <p>p.s. I do not think that question title is really good and probably this is well known problem which has an established name, so if one can point it out I'll be really glad to swap the title. </p>