# observe\_custom\_pivot/2

Source: https://zotonic.com/docs/2094/observe_custom_pivot-2

URI: https://zotonic.com/id/2094

Language: en



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](/id/doc_developerguide_notifications#notification-map)

Return:

`#custom_pivot{}` properties:

- id: `m_rsc:resource_id()`

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2094?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2094?language=en>)
