title: How to create a relationship between two objects in Rails has_many_and_belongs_to_many relationship
body: <p>I have the following models:</p>
  
  <pre><code>class Match &lt; ActiveRecord::Base
  
  has_and_belongs_to_many :teams
  
  end 
  </code></pre>
  
  <p>And</p>
  
  <pre><code>class Team &lt; ActiveRecord::Base
  
  has_and_belongs_to_many :matches
  
  end
  </code></pre>
  
  <p>They are joined together with a matches_teams table.</p>
  
  <p>It seems I have things set up correctly. I can get @team.matches to work, for instance.</p>
  
  <p>My question is how would I go about assigning two specific teams to a match? In the rails console I can go: @team.match.create and that works, but it creates a new match associated with that team. How do I had another team to that association?</p>
  
  <p>I'm fairly new to Rails if that wasn't already obvious. Thanks!</p>