【问题标题】:apostrophe cms data retrieval of join of pieces with join of another piece撇号 cms 数据检索块的连接与另一块的连接
【发布时间】:2021-01-16 01:27:43
【问题描述】:

**下面给出的代码是一个名为 home 的片段的架构字段,并且 home 有与之相连的片段,例如 _trip、_accomodation、_testimonial。这些连接的片段再次与它们的模式中的其他片段连接。所以检索使用 api/v1/home 的 home 部分,连接部分的内部连接显示为 id。

如何获取该 id 的数据???**

 {
      name: '_trip',
      label: 'Spotlight Trips',
      limit:4,
      type: 'joinByArray',
      withType: 'trip',
    },
    {
      name: '_accommodation',
      label: 'Spotlight Accommodations',
      type: 'joinByArray',
      withType: 'accommodation',
      limit:2,
    },
    {
      name: '_testimonial',
      label: 'Testimonials',
      type: 'joinByArray',
      withType: 'testimonial'
    },

下面给出的 json 是检索数据的一部分。我想获取另一部分的住宿和旅行数据,但这里显示的是它的 id。

"_home-spotlight": [
        {
          "_id": "cki5owqrv008obgundta0x6rp",
          "published": true,
          "trash": false,
          "type": "home-spotlight",
          "title": "spotlightAbove",
          "tripIds": [
            "cki5oqi7r0063bgun81o6umqd"
          ],
          "accommodationIds": [
            "cki5owga1008mbgunlxweuera"
          ],

【问题讨论】:

  • 如果您在那里看到accommodationIds,默认情况下您可能还会在REST API 响应中看到_accommodation。你得到两个。其他连接也一样。
  • 不,我看不到它 _home-spotlight 已经是家庭的一部分,家庭聚光灯已将其作为旅行和住宿的一部分加入其中,因此仅显示为 id 我需要该数据@alexbea
  • 您上面的描述中可能缺少某些内容。您是否有一个名为home 的片段连接到另一个称为home-spotlight 的片段,然后home-spotlight 连接到其他三种片段类型?你得到了home 块,但还想要来自连接的home-spotlight 和连接到home-spotlight 的其他三个中的任何数据?
  • 是的,这是我的确切要求,你能帮我吗@alexbea
  • 在正常使用中(不通过 REST API 访问),您将使用此处记录的 withJoins 数组选项:docs.apostrophecms.org/reference/field-types/…。这将包括随后加入的文档的数据。无头模块目前可能不支持该选项。您的短期解决方案可能是使用您收到的 ID 拨打额外的电话。如果您在apostrophe-headless repo 中打开一个关于此的问题,也会很有帮助。

标签: apostrophe-cms


【解决方案1】:

目前,ApostropheCMS 无法通过 Rest API 从内部连接(即集合连接有另一个集合连接)中获取内容。目前,我们将只获取该集合的 ID。因此,alexbea 说,我们必须执行另一个额外的 API 调用来使用 ID 获取该集合。

不使用 Rest API 的用户可以使用 withJoins 获取这些集合 [https://docs.apostrophecms.org/reference/field-types/joinbyarray.html#settings]。

【讨论】:

    猜你喜欢
    • 2021-09-22
    • 1970-01-01
    • 2019-01-30
    • 2021-10-03
    • 2012-04-06
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多