"0" key on the input_for nested associations

Trying to build an association for a has_many from a multiple_select.

While examining the log, I noticed that input_for stores every child under "0" key in a map.

In my case, this is what I have in template

<div>
    <%= label fp, :languages %>
    <%= multiple_select fp, :value, Enum.map(@languages, fn x -> {x.id, x.value} end) %>
</div>
<% end %>

This is what I see when inspecting struct going to :create

%{"languages" => %{"0" => %{"value" => ["3"]}}}

Any additional form result inside the input_for is put inside the map under the key “0”.

My question is what is so special about this “0”? Where is it coming from?

Likely your form field is named something[], meaning it’s a list?