{"result":{"depiction_url":null,"edges":{"hasreference":{"objects":[{"created":"2026-10-07T11:13:39Z","object_id":{"id":2962,"is_a":["text","documentation","developerguide"],"name":"developer_schema_upgrades","title":{"_type":"trans","tr":{"en":"Upgrade a module&#39;s data schema"}},"uri":"https:\/\/zotonic.com\/id\/2962"},"seq":1},{"created":"2026-10-07T11:13:39Z","object_id":{"id":1282,"is_a":["text","documentation","cookbook"],"name":"doc_cookbook_pivot_templates","title":{"_type":"trans","tr":{"en":"Pivot Templates"}},"uri":"https:\/\/zotonic.com\/id\/1282"},"seq":2}],"predicate":{"id":2774,"is_a":["meta","predicate"],"name":"hasreference","title":{"_type":"trans","tr":{"en":"Documentation reference"}},"uri":"https:\/\/zotonic.com\/id\/hasreference"}},"references":{"objects":[{"created":"2020-05-30T05:47:53Z","object_id":{"id":1638,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_search","title":{"_type":"trans","tr":{"en":"Search"}},"uri":"https:\/\/zotonic.com\/id\/1638"},"seq":1000000},{"created":"2020-05-30T05:47:53Z","object_id":{"id":1276,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_resources","title":{"_type":"trans","tr":{"en":"Use stable resource names"}},"uri":"https:\/\/zotonic.com\/id\/1276"},"seq":1000000}],"predicate":{"id":332,"is_a":["meta","predicate"],"name":"references","title":{"_type":"trans","tr":{"en":"References"}},"uri":"https:\/\/zotonic.com\/id\/references"}},"relation":{"objects":[{"created":"2020-05-30T05:47:53Z","object_id":{"id":1638,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_search","title":{"_type":"trans","tr":{"en":"Search"}},"uri":"https:\/\/zotonic.com\/id\/1638"},"seq":1000000},{"created":"2020-05-30T05:47:53Z","object_id":{"id":1282,"is_a":["text","documentation","cookbook"],"name":"doc_cookbook_pivot_templates","title":{"_type":"trans","tr":{"en":"Pivot Templates"}},"uri":"https:\/\/zotonic.com\/id\/1282"},"seq":1000000}],"predicate":{"id":303,"is_a":["meta","predicate"],"name":"relation","title":{"_type":"trans","tr":{"nl":"Relatie","en":"Relation"}},"uri":"http:\/\/purl.org\/dc\/terms\/relation"}},"subject":{"objects":[{"created":"2026-10-07T11:13:39Z","object_id":{"id":2557,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_cookbook_recipe","title":"Cookbook recipe","uri":"https:\/\/zotonic.com\/id\/2557"},"seq":1},{"created":"2026-10-07T11:13:40Z","object_id":{"id":2564,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_backend_developer","title":"Backend developer","uri":"https:\/\/zotonic.com\/id\/2564"},"seq":2},{"created":"2026-10-07T11:13:40Z","object_id":{"id":2629,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_pivot_index","title":"Pivot and search index","uri":"https:\/\/zotonic.com\/id\/2629"},"seq":3},{"created":"2026-10-07T11:13:40Z","object_id":{"id":2631,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_database","title":"Database","uri":"https:\/\/zotonic.com\/id\/2631"},"seq":4},{"created":"2026-10-07T11:13:40Z","object_id":{"id":2586,"is_a":["categorization","keyword","keyword_domain"],"name":"zotonic_topic_search_and_discovery","title":"Search and discovery","uri":"https:\/\/zotonic.com\/id\/2586"},"seq":5}],"predicate":{"id":308,"is_a":["meta","predicate"],"name":"subject","title":{"_type":"trans","tr":{"en":"Keyword"}},"uri":"http:\/\/purl.org\/dc\/elements\/1.1\/subject"}}},"id":1281,"is_a":["text","documentation","cookbook"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1281"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_cookbook_custom_pivot","page_url":{"en":"https:\/\/zotonic.com\/cookbook\/1281\/index-a-custom-resource-property","x-default":"https:\/\/zotonic.com\/cookbook\/1281\/index-a-custom-resource-property"},"preview_url":null,"resource":{"body":{"_type":"trans","tr":{"en":"<p>Use a custom pivot when a resource property must be filtered or sorted in SQL. Define the table in the active module&#39;s schema callback, and increase <code>-mod_schema(...)<\/code> when adding it to an already installed module:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">manage_schema(_Version, Context) -&gt;\n    ok = z_pivot_rsc:define_custom_pivot(garden,\n        [{requestor, &quot;text&quot;}], Context),\n    ok.\n<\/code><\/pre>\n<p>Merge this operation into existing schema handling; do not replace unrelated upgrades. Export <code>manage_schema\/2<\/code> and <code>observe_custom_pivot\/2<\/code>, and include <code>zotonic.hrl<\/code>:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">observe_custom_pivot(#custom_pivot{id = Id}, Context) -&gt;\n    {garden, [{requestor, m_rsc:p(Id, requestor, Context)}]}.\n<\/code><\/pre>\n<p>The table is <code>pivot_garden<\/code>. The current helper alters the table when column names differ; do not rely on the old claim that every definition change drops and recreates it. A type change with the same column names needs an explicit, reviewed database migration.<\/p>\n<p>Compile and activate the module upgrade, then rebuild search indexes from the site&#39;s status tools. Wait for pivoting to complete. Save a practice resource with a <code>requestor<\/code> property and check both filtering and sorting:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-django\">{% for result_id in m.search[{query filter=[&quot;pivot.garden.requestor&quot;, `=`, &quot;Alice&quot;] sort=&quot;pivot.garden.requestor&quot;}] %}\n    &lt;p&gt;{{ result_id.title }}&lt;\/p&gt;\n{% endfor %}\n<\/code><\/pre>\n<p>Test as the intended user so visibility rules still apply. Defining a column alone does not populate existing resources.<\/p>"}},"category_id":{"id":318,"is_a":["meta","category"],"name":"cookbook","title":{"_type":"trans","tr":{"en":"Cookbook"}},"uri":"https:\/\/test.zotonic.com\/id\/318"},"content_group_id":{"id":339,"is_a":["meta","content_group"],"name":"default_content_group","title":{"_type":"trans","tr":{"en":"Default Content Group"}},"uri":"https:\/\/zotonic.com\/id\/default_content_group"},"created":"2020-05-30T05:47:16Z","creator_id":{"id":336,"is_a":["person","robot"],"name":"gitbot","title":"Git","uri":"https:\/\/zotonic.com\/id\/336"},"doc_editorial_bundle":true,"doc_editorial_edges":{"hasreference":[1282,2962],"subject":[2557,2564,2586,2629,2631]},"github_url":"https:\/\/github.com\/zotonic\/zotonic\/tree\/master\/doc\/cookbook\/custom-pivot.rst","is_authoritative":true,"is_dependent":false,"is_featured":false,"is_protected":false,"is_published":true,"is_unfindable":false,"language":["en"],"modified":"2026-10-07T11:13:49Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"name":"doc_cookbook_custom_pivot","pivot_geocode":null,"pivot_location_lat":null,"pivot_location_lng":null,"privacy":0,"publication_end":"9999-06-01T00:00:00Z","publication_start":"2022-02-15T10:01:32Z","slug":"index-a-custom-resource-property","summary":{"_type":"trans","tr":{"en":"Create a pivot column and fill it through the custom_pivot notification."}},"title":{"_type":"trans","tr":{"en":"Index a custom resource property"}},"title_slug":{"_type":"trans","tr":{"en":"index-a-custom-resource-property"}},"tz":"UTC","uri":null,"version":35,"visible_for":0},"uri":"https:\/\/zotonic.com\/id\/1281","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1281"}},"status":"ok"}