I have a multiple_select to select a single medic for an appointment, I managed to show up a list to choose a medic, and when inspecting the element it does have an id as a value, the thing is that when trying to add an appointment it will give an error is invalid in the medic field.
This is my form:
schema "appointments" do
field :bloque, :integer
field :descripcion, :string
field :fecha, :date
field :id_medico, :integer
field :rut_paciente, :string
timestamps()
end
It seems like has_many/belongs_to, but You do not define association.
I would add those… like this
schema "appointments" do
field :bloque, :integer
field :descripcion, :string
field :fecha, :date
field :rut_paciente, :string
belongs_to :medico, Medico
timestamps()
end
schema "medicos" do
...
has_many :appointments, Appointment
timestamps()
end
I also doubt about this, because a medico could potentially have may appointment, but here You say something else… You say there should be only one appointment with id_medico = x
Also, the unique constraint is there to avoid mutliple appointments with the same date, block and medic, the combination of these three attributes must be unique.
I’m sorry, I’m unfamiliar with IO.inspect, I did google for a while and inserted into the create action, but I don’t know where should I see the output, also I’m thinking I should just remake the table with belongs_to and has_many and avoid using :id_medico as an attribute name.
The medics table is now plural, but what is the name of your Schema? Medic or Medics?
The schema is usually singular, and it can cause some trouble, in particular the way you will name association. You will use singular for has_one, belongs_to but plural for has_many, many_to_many
As I see your key, I guess You have defined a Medics schema, as a plural form.
IO.inspect logs to the running console, where You started the server…
Yes, tried with both medic and medics, medic returns (with Clinic.Medic):
ERROR 42703 (undefined_column): column a0.medic_id does not exist,
could it be because I used id_medico as an attribute (I removed it in appointment).