Ash FrameworkAF
Ash Framework3y ago
13 replies
richaard0

AshPhoenix potential bug with relationships

I have the following form:

    <.simple_form
      :let={f}
      for={@form}
      id="add-flight-form"
      phx-submit="submit"
      phx-change="validate"
    >
      <.input
        field={{f, :plane}}
        type="select"
        label="Airplane"
        options={Enum.map(@fleet, & &1.registration)}
      />
      <.input field={{f, :number}} label="Number" />
      <.input field={{f, :departure}} label="Departure" />
      <.input field={{f, :arrival}} label="Arrival" />
      <.input field={{f, :alternate}} label="Alternate" />
      <:actions>
        <.button>Save</.button>
      </:actions>
    </.simple_form>


I do get an error if the number or plane field is missing, but I don't have any errors for the departure, arrival and alternate fields.

All 3 of these fields have a similar relationship on my resource that looks like this:

    belongs_to :departure_airport, Vigil.Airports.Airport do
      api Vigil.Airports
      attribute_writable? true
      allow_nil? false
      source_attribute :departure
      destination_attribute :icao_code
      attribute_type :string
    end

If I inspect the form, I don't see any errors at all regarding those fields, as if they weren't attributes at all, but I do see the attributes data:

attributes: %{alternate: nil, arrival: nil, departure: nil, number: nil},

Shouldn't the form show errors about those fields being required?
Was this page helpful?