Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fill arrays of references in a single query

Tags:

sanity

groq

I have a schema type Page which has an array of blocks:

{
  title: 'Page',
  name: 'page',
  type: 'document',
  fields: [
    ...
    {
      title: 'Blocks',
      name: 'blocks',
      type: 'array',
      of: [
        {type: 'tileGrid'},
        {type: 'otherType'}
      ],
      options: {
        editModal: 'fullscreen'
      }
    }
  ]
}

The type tileGrid has the following fields:

{
      title: 'Tiles',
      name: 'tiles',
      type: 'array',
      of:  [{
        type: 'reference',
        to: [
          {type: 'tile'}
        ]
      }]
}

So the tile type is deeply nested page.blocks[].tiles[].tile. How can I query page and fill in the tile references in the same query?

like image 931
Slem Avatar asked Oct 18 '22 00:10

Slem


1 Answers

Since tile is a reference, you need the dereferencing operator, rather than the dot operator. This should work: page.blocks[].tiles[]->.

like image 131
svale Avatar answered Oct 21 '22 02:10

svale