# `Backpex.Fields.HasMany`
[🔗](https://github.com/naymspace/backpex/blob/0.18.3/lib/backpex/fields/has_many.ex#L2)

A field for handling a `has_many` or `many_to_many` relation.

This field can not be orderable or searchable.

## Field-specific options

See `Backpex.Field` for general field options.

* `:display_field` (`t:atom/0`) - Required. The field of the relation to be used for searching, ordering and displaying values.

* `:display_field_form` (`t:atom/0`) - The field to be used to display form values.

* `:live_resource` (`t:atom/0`) - The live resource of the association.

* `:link_assocs` (`t:boolean/0`) - Whether to automatically generate links to the association items. The default value is `true`.

* `:options_query` (function of arity 2) - Manipulates the list of available options in the multi select.

  Defaults to `fn (query, _field) -> query end` which returns all entries.

* `:prompt` - The text to be displayed when no options are selected or function that receives the assigns.

  The default value is `"Select options..."`.

* `:not_found_text` (`t:String.t/0`) - The text to be displayed when no options are found.

  The default value is `"No options found"`.

* `:query_limit` - Limit passed to the query to fetch new items. Set to `nil` to have no limit. The default value is `10`.

## Example

    @impl Backpex.LiveResource
    def fields do
    [
      posts: %{
        module: Backpex.Fields.HasMany,
        label: "Posts",
        display_field: :title,
        options_query: &where(&1, [user], user.role == :admin),
        live_resource: DemoWeb.PostLive
      }
    ]
    end

# `assign_selected`

# `config_schema`

Returns the schema of configurable options for this field.

This can be useful for reuse in other field modules.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
