View Source Backpex.Fields.HasManyThrough (Backpex v0.8.1)
A field for handling a has_many
(through
) relation.
This field is not orderable or searchable.
Warning
This field is in beta state. Use at your own risk.
Options
:display_field
- The field of the relation to be used for displaying options in the select.:live_resource
- The corresponding live resource of the association. Used to display the title of the modal and generate defaults for:child_fields
fields.:sort_by
- A list of columns by which the child element output will be sorted. The sorting takes place in ascending order.:child_fields
- WIP:pivot_fields
- List to map additional data of the pivot table to Backpex fields.:options_query
- Manipulates the list of available options in the select. Can be used to select additional data for thedisplay_field
option or to limit the available entries. Defaults tofn (query, _field) -> query end
which returns all entries.
Example
@impl Backpex.LiveResource
def fields do
[
addresses: %{
module: Backpex.Fields.HasManyThrough,
label: "Addresses",
display_field: :street,
live_resource: DemoWeb.AddressLive,
sort_by: [:zip, :city],
pivot_fields: [
type: %{
module: Backpex.Fields.Select,
label: "Address Type",
options: [Shipping: "shipping", Billing: "billing"]
}
]
}
]
end
The field requires a Ecto.Schema.has_many/3
relation with a mandatory through
option in the main schema. Any extra column in the pivot table besides the relational id's must be mapped in the pivot_fields
option or given a default value.