【问题标题】:Apostrophe CMS: Get piece data in nested join (joinByArray – joinByOne)Apostrophe CMS:在嵌套连接中获取片段数据(joinByArray – joinByOne)
【发布时间】:2018-12-16 03:40:31
【问题描述】:

我在从嵌套连接中获取片段数据时遇到问题:joinByArray – joinByOne。我尝试在连接中使用投影过滤器并忽略它们——它不起作用(以不同的方式,但结果是相同的——没有连接的片段数据)。

这是我的设置。我定义了两个部分:

作者:

extend: 'apostrophe-pieces',
name: 'author',
// ...
addFields: [
{
  name: 'photo',
  label: 'Photo',
  required: true,
  type: 'singleton',
  widgetType: 'apostrophe-images',
  options: {
    limit: [ 1 ]
  }
},
// ...

出版:

extend: 'apostrophe-pieces',
name: 'publication',
// ...
addFields: [
{
  name: '_author',
  label: 'Author',
  type: 'joinByOne',
  withType: 'author',
  idField: 'authorId',
  filters: {
    projection: {
      slug: 1,
      type: 1,
      tags: 1,
      title: 1,
      photo: 1
    }
  }
},
// ...

然后我创建了一个这样的出版物页面:

extend: 'apostrophe-pieces-pages',
name: 'publications-page',
// ...
addFields: [
{
  name: '_featured',
  label: 'Featured Publications',
  type: 'joinByArray',
  withType: 'publication',
  idsField: 'featuredIds',
  filters: {
    projection: {
      slug: 1,
      title: 1,
      type: 1,
      // ...
      _author: 1
    }
  },
  relationship: [
    // ...
  ]
},
// ...

如您所见,_featured 是应该显示在页面顶部的精选出版物列表,然后是其他出版物的列表。我需要所有数据才能正确显示它们,包括作者姓名 (title) 和照片。

问题是我在 Nunjucks 模板中得到:

  • authorId 仅当我将 projection 用于 _featured 加入时
  • 如果我为 _featured 加入省略 projection,则根本没有作者数据的迹象

出版物的一般列表(可通过 Nunjucks index.html 模板中的 data.pieces 获得)是完美的并且包含所有数据。而data.page._featured 没有。

我的问题:有没有办法告诉 Apostrophe CMS 从上述嵌套连接中获取数据?那么要在出版物页面上获取“特色”出版物的作者作品数据吗?

我喜欢这种设置,我更愿意保持这种方式。但如果我需要更改某些内容(例如,使用 singleton 而不是 joinByOne),我也可以尝试一下。

【问题讨论】:

    标签: apostrophe-cms


    【解决方案1】:

    我认为您想将withJoins: true 添加到您的_featured 加入配置中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多