【问题标题】:How to fill arrays of references in a single query如何在单个查询中填充引用数组
【发布时间】:2018-06-25 01:44:16
【问题描述】:

我有一个架构类型页面,它有一个块数组:

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

tileGrid 类型有以下字段:

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

所以tile 类型深深嵌套在page.blocks[].tiles[].tile 中。 如何查询page并在同一查询中填写tile引用?

【问题讨论】:

    标签: sanity groq


    【解决方案1】:

    由于 tile 是引用,因此您需要取消引用运算符,而不是点运算符。这应该可以工作:page.blocks[].tiles[]->

    【讨论】:

    • 您将如何构建查询?这是我尝试过的:*[_type == "page"]{_id, name, route, blocks, blocks[].tiles[]->tile}}
    • 每当您构建复杂的链或类似的任意查询时,您可能都必须命名该字段。像这样:*[_type == "page"]{_id, name, route, "blocks": blocks[].tiles[]->}}(在取消引用运算符之后删除tile,这将从所引用的内容中提取字段“平铺”,而只需添加箭头即可扩展引用所指向的内容)
    猜你喜欢
    • 1970-01-01
    • 2016-03-03
    • 2016-03-03
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 2020-12-29
    相关资源
    最近更新 更多