Apostrophe CMS:在嵌套连接中获取片段数据(joinByArray – joinByOne)
Apostrophe CMS: Get piece data in nested join (joinByArray – joinByOne)
我在从嵌套连接获取片段数据时遇到问题: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
join ,则根本没有作者数据的迹象
出版物的总清单(可通过 Nunjucks index.html
模板中的 data.pieces
获得)是完美的并且包含所有数据。虽然 data.page._featured
没有。
我的问题:有没有办法告诉 Apostrophe CMS 从上面的嵌套连接中获取数据?因此,要在出版物页面上获取 "featured" 出版物的作者文章数据?
我喜欢这个设置,我更愿意保持这种状态。但是如果我需要改变一些东西(例如在 joinByOne
上使用 singleton
),我也可以尝试。
我认为您想将 withJoins: true
添加到您的 _featured
加入配置
我在从嵌套连接获取片段数据时遇到问题: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
join ,则根本没有作者数据的迹象
出版物的总清单(可通过 Nunjucks index.html
模板中的 data.pieces
获得)是完美的并且包含所有数据。虽然 data.page._featured
没有。
我的问题:有没有办法告诉 Apostrophe CMS 从上面的嵌套连接中获取数据?因此,要在出版物页面上获取 "featured" 出版物的作者文章数据?
我喜欢这个设置,我更愿意保持这种状态。但是如果我需要改变一些东西(例如在 joinByOne
上使用 singleton
),我也可以尝试。
我认为您想将 withJoins: true
添加到您的 _featured
加入配置