title: Rails has_many undefined method for association
body: <p>I have two objects: <code>Team</code> and <code>Player</code>.  As you could probably guess, a <code>Team</code> has many <code>Players</code> and a <code>Player</code> belongs to a team.</p>
  
  <p>I understand that we can model this relationship with another model, <code>Team_Players</code> but I want to focus on the raw relationship here, as shown by many of the guides I'm seeing online.</p>
  
  <p>When creating <code>Player</code>s, it's easy to assign them a <code>Team.id</code>, since they only have one, but the reverse -<code>has_many</code>- is more complicated.  The <a href="http://guides.rubyonrails.org/association_basics.html" rel="nofollow">Rails guide on associations</a> only shows the model file, so this is what mine looks like in reflection:</p>
  
  <pre><code>class Team &lt; ActiveRecord::Base
    has_many :players
  end
  </code></pre>
  
  <p>Now, I would expect to be able to do something like <code>Team.first.players</code> and be given an array or something, but instead I just get <code>undefined method player for #&lt;Team:0x&gt;</code> and in fact in <a href="https://www.youtube.com/watch?v=kI9KIh4ycAk" rel="nofollow">this video</a>, I do see a developer doing something just like that.  So what am I missing?  Do I <em>have</em> to make an intersection model here?  I would imagine not since <code>has_many</code> is inherent in Rails.</p>
  
  <p>After creating the tables, I added the reference for <code>Team</code> to <code>Player</code> in this migration:</p>
  
  <pre><code>def change
    add_reference :players, :team, index: true
    add_foreign_key :players, :team
  end
  </code></pre>
  
  <p>Again, since the has many relationship can't be modeled with a single column, I avoided that part in the migration.  Is that what's necessary for the desired functionality of <code>Team.first.players</code> returning an array or something?</p>