How to fill arrays of references in a single query

How to fill arrays of references in a single query



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:


tileGrid



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?


tile


page.blocks.tiles.tile


page


tile




1 Answer
1



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


page.blocks.tiles->





How would you structure the query? This is what I've tried: *[_type == "page"]_id, name, route, blocks, blocks.tiles->tile}
– Slem
Jan 16 at 12:51


*[_type == "page"]_id, name, route, blocks, blocks.tiles->tile}





Whenever you build complex chains or arbitrary queries like that, you probably have to name that field. Something like this: *[_type == "page"]_id, name, route, "blocks": blocks.tiles->} (Remove the tile after the dereferencing operator, this would extract the field "tile" from whatever is referred to, while just adding the arrow expands whatever is pointed to by the reference)
– svale
Jan 16 at 14:38


*[_type == "page"]_id, name, route, "blocks": blocks.tiles->}


tile





Thanks! That worked!
– Slem
Jan 18 at 12:17






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ