title: Array of foreign keys in Ecto (Phoenix)
body: <p>I'm a beginner in web dev so excuse my lack of knowledge.</p>
  
  <p>I have a <code>Teacher</code> and a <code>Student</code> Ecto schema. They are supposed to be linked via another schema called <code>Class</code> by following these rules:</p>
  
  <ol>
  <li><p>Each class has only one teacher, and has an array of students.</p></li>
  <li><p>Each teacher can be part of many classes</p></li>
  <li><p>Each student can be part of many classes.</p></li>
  </ol>
  
  <p>Here's the schema I've built so far:</p>
  
  <pre><code># Part of student.ex
  schema "students" do
      field :active, :boolean, default: false
      field :birthday, :date
      field :email, :string, unique: true
      field :firstname, :string
      field :lastname, :string
      field :phone, :string, unique: true
      belongs_to :classes, Class, foreign_key: :class_id
      many_to_many :teachers, Users.Teacher, join_through: "classes"
  
      timestamps()
    end
  </code></pre>
  
  <pre><code># Part of teacher.ex
  schema "teachers" do
      field :active, :boolean, default: false
      field :birthday, :date
      field :email, :string, unique: true
      field :firstname, :string
      field :lastname, :string
      field :phone, :string, unique: true
      belongs_to :classes, Class, foreign_key: :class_id
      many_to_many :students, Users.Student, join_through: "classes"
      timestamps()
    end
  </code></pre>
  
  <pre><code># Part of class.ex
  schema "classes" do
      field :end_date, :date
      field :time, :time
      field :level, :string
      field :start_date, :date
      field :title, :string
      has_many :students, Users.Student
      has_one :teacher, Users.Teacher
      embeds_many :sessions, Session
      timestamps()
    end
  </code></pre>
  
  <p>Things look ok here. But the problem is, how do I specify "an array of student ids" in my migration file? Here are the migration functions:</p>
  
  <pre><code># Part of students migration file. It's the same for teachers.
  def change do
      create table(:students) do
        add :firstname, :string, null: false, size: 32
        add :lastname, :string, null: false, size: 32
        add :phone, :string, null: false, size: 16
        add :email, :string, size: 32
        add :birthday, :date
        add :active, :boolean, default: false, null: false
  
        timestamps()
      end
  
      create(unique_index(:students, [:phone]))
    end
  </code></pre>
  
  <p>This is where I'm really stuck at right now:</p>
  
  <pre><code>def change do
      create table(:classes) do
        add :title, :string, null: false
        add :level, :string
        add :hours, :string, null: false
        add :start_date, :date
        add :end_date, :date
        add :teacher_id, references(:teachers), primary_key: true
        # HERE! How do I create a column for an array of student_id foreign keys?
        timestamps()
      end
  
      create(index(:classes, [:teacher_id]))
  
    end
  </code></pre>
  
  <p>Thanks in advance.</p>