Backpex.Fields.HasManyThrough (Backpex v0.15.2)
View SourceA 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.
Field-specific options
See Backpex.Field for general field options.
:display_field(atom/0) - Required. The field of the relation to be used for displaying options in the select.:live_resource(atom/0) - Required. The corresponding live resource of the association. Used to display the title of the modal and generate defaults for:child_fieldsfields.:sort_by(list ofatom/0) - A list of columns by which the child element output will be sorted. The sorting takes place in ascending order.:child_fields(keyword/0) - WIP:pivot_fields(keyword/0) - List to map additional data of the pivot table to Backpex fields.:options_query(function of arity 2) - Manipulates the list of available options in the select. Can be used to select additional data for thedisplay_fieldoption or to limit the available entries.",Defaults to
fn (query, _field) -> query endwhich 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"]
}
]
}
]
endThe 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.
Summary
Functions
Returns the schema of configurable options for this field.