title: Rails Association: Teacher Student Classes
body: <p>I'm still learning to get creative with Rails and could use some guidance on best practice for the following Rails association:</p>
  
  <p>I have three models, Teachers, Students, &amp; Classes. Teachers can teach any numbers of classes, students can join any number of classes, and a class is only taught by one teacher but can have 1-5 students. </p>
  
  <p>My first assumption is to use the follwing:</p>
  
  <p>Class:
  belongs_to teacher
  has_many Students</p>
  
  <p>Teachers:
  has_many: students through => classes</p>
  
  <p>Students:
  has_many: teachers through => classes</p>
  
  <p>I don't know if this is appropriate and I've seen suggestions for joining tables. Any guidance would be appreciated ! </p>
  
  <p><strong>Update: Given the feedback from the helpful users below, I'm suggesting the following solution. Can someone please verify this? Because a student can have many classes and belong to a class, and visa versa, I need two join tables</strong></p>
  
  <pre><code>class ClassRoomEnrollment &lt; ActiveRecord::Base
   belongs_to :students
   belongs_to :classrooms
  end
  
  class ClassRoom &lt; ActiveRecord::Base
   belongs_to :teacher
   has_many :students through: classroomenrollment 
  
  end
  
  class Teacher &lt; ActiveRecord::Base
   has_many :students :through =&gt; :classrooms
  end
  
  class Student &lt; ActiveRecord::Base
   has_many :teachers :through =&gt; :classrooms
   has_many :classrooms through: classroomenrollment 
  end
  </code></pre>