Value is invalid in multiple_select

You might show the appointment migration file.

defmodule Medica.Repo.Migrations.CreateAppointments do
  use Ecto.Migration

  def change do
    create table(:appointments) do
      add :rut_paciente, :string
      add :fecha, :date
      add :id_medico, references(:medics)
      add :bloque, :integer
      add :descripcion, :text

      timestamps()
    end
    create unique_index(:appointments, [:fecha, :bloque, :id_medico])
  end
end

Well it’s clearer now, You don’t have this key.

Replace

add :id_medico, references(:medics)

# with 

add :medic_id, references(:medics)

Or use foreign_key options to specify a custom key.

That may be it, it was wrong to mix some spanish in between haha, thanks, I’ll do that and check again the multiple_select.

Ok, I did everything and now it does’nt give phoenix errors, but It keeps giving is_invalid error under the medics field.

%{
  "bloque" => "25",
  "descripcion" => "Example",
  "fecha" => %{"day" => "1", "month" => "9", "year" => "2013"},
  "medic_id" => ["2"],
  "rut_paciente" => "19.386.399-K"
}

It does send the correct data though.

It does not because You use multiselect


"medic_id" => ["2"],

# but You are expecting an id, like this

"medic_id" => "2",

It returns a list of id, so You need to unwrap and take first :slight_smile:

1 Like

That did the trick, thanks.