View Source Backpex.Fields.BelongsTo (Backpex v0.8.1)
A field for handling a belongs_to
relation.
Options
:display_field
- The field of the relation to be used for searching, ordering and displaying values.:display_field_form
- Optional field to be used to display form values.:live_resource
- The live resource of the association. Used to generate links navigating to the association.:options_query
- Manipulates the list of available options in the select. Defaults tofn (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.
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