N:m Pivot Filter


Permit to filter a list using a Many-to-Many relation table.
Pivot Filter

For instance, in the 'Cities' table, the user is able to filter on 'Travellers'
The pivot table is 'Visits', which contains a FK to a City, and a FK to a Traveller.

This filter is multi-selection. It means that you can concat multiple values into the filter.

Pivot Filter Multiselect

Instance a pivot filter

N:m Node

1. In the builder, instance the 'List' Filter into the filters drop area of your list layout.

2. Then, drop a N:m table relation node into the filter.

In the builder, from the Local layout (ex: Cities),
- Open a the Pivot Table (ex : Visits)
- Find and drag the Foreign table node (ex: Travellers)
You can eventually open this Foreign Table node and choose the label field. (ex: Name)
By default (when you don't specify the Foreign Table label field), the label field will be the default field of the table (Yellow star)

Source code

In ModelList :: prepareQuery(), the function :


In XML file :


Logic for multiple values (AND, OR, NOT)

You can customize the logic behaviors using the state vars.
(For our example, 'travellers', is the name of the relation)
Remember that the states var must be initialized BEFORE getItems() of the model.

// Match At least one value
$this->setState('filter.travellers.logic', 'OR');
// Match All values
$this->setState('filter.travellers.logic', 'AND');
// Exclude All values
$this->setState('filter.travellers.logic', 'NOT');

Get Started