Ash FrameworkAF
Ash Framework3y ago
2 replies
Robert Graff

How to set belongs_to on in a form

I have a create action for Plan that sets the Product (Plan belongs_to Product)

    create :create do
      primary? true
      argument :product, :map, allow_nil?: false
      change manage_relationship(:product, :product, type: :append)
    end


I have a form that I create like this...

    create_plan_form =
      AshPhoenix.Form.for_create(Plan, :create, api: Environments)
      |> to_form()
      |> AshPhoenix.Form.add_form([:product])


and then a select input

          <.inputs_for :let={product_form} field={@create_plan_form[:product]}>
            <.input
              type="select"
              field={{product_form, :id}}
              options={@product_options}
              label="Product"
            />
          </.inputs_for>


This raises an error:
product at path [] must be configured in the form to be used with `inputs_for`.


I tried forms: [auto?: true] and then I don't get an error but I also don't get any field.
Was this page helpful?