Saving an association from a select input

Thanks @shd42, indeed the select is more appropriate, didn’t know this, I have never used forms.

So if you change your view to use the select instead of the input, you will receive an attrs that looks like this

%{
    ...
    "session_id" => 5,
    ...
}

Then you simply have to cast it

  @fields [:firstname, :lastname, :session_id]
  @required_fields [:firstname, :lastname, :session_id]

  def changeset(student, attrs) do
    student
    |> cast(attrs, @fields)
    |> validate_required(@required_fields)
  end

But this is true only if the foreign_key name in your table is named session_id.

Wich seems to not to be the case, because you overrided it:

  belongs_to :session, Session, foreign_key: :bold_session

Any reason for this ? what was the intention ?

If you need this field ne be named bold_session, just change session_id to bold_session in both changeset and your view.