observe_custom_pivot/2

Add custom pivot fields to a resource’s search index (map) Result is a single tuple or list of tuples {pivotname, props}, where “pivotname” is the pivot defined in a call to z_pivot_rsc:define_custom_pivot/3 or a table with created using a SQL command during (eg.) in a module manage_schema/2 call. The name of the table is pivot_<pivotname>. The props is either a property list or a map with column/value pairs.

For a sparse custom pivot, return {pivotname, undefined} when the resource needs no row in that pivot table. This deletes any existing row for the resource and succeeds if no row exists. A later {pivotname, props} result inserts the row again. Named results can also be returned in a list. Returning bare undefined, none, or ok leaves existing custom pivot rows unchanged.

For example, an observer can return {my_pivot, #{value => Value}} for matching resources and {my_pivot, undefined} for resources that no longer match.

The table MUST have an id column, with a foreign key constraint to the rsc table. If you define the pivot table using z_pivot_rsc:define_custom_pivot/3 then this column and foreign key constraint are automatically added.

Type:

map

Return:

#custom_pivot{} properties:

  • id: m_rsc:resource_id()

Edit on GitHub

Observed by

Modules

mod_search

mod_search implements various ways of searching through the main resource table using model#search.