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

A field for handling a `belongs_to` relation.

## 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`) - Field to be used to display form values.

* `:live_resource` (`t:atom/0`) - The live resource of the association. Used to generate links navigating to the association.

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

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

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

* `:debounce` - Timeout value (in milliseconds), "blur" or function that receives the assigns.

* `:throttle` - Timeout value (in milliseconds) or function that receives the assigns.

## Example

    @impl Backpex.LiveResource
    def fields do
    [
      user: %{
        module: Backpex.Fields.BelongsTo,
        label: "Username",
        display_field: :username,
        options_query: &where(&1, [user], user.role == :admin),
        live_resource: DemoWeb.UserLive
      }
    ]
    end

# `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*
