我的作品类型为project
,其作品类型为_author
,可以是两种不同的类型:
module.exports = {
extend: 'apostrophe-pieces',
name: 'project',
label: 'Project',
pluralLabel: 'Projects',
addFields: [
{
label: 'Creator',
help: 'Person or collective who created the project.',
name: '_author',
idsField: 'creatorIds',
type: 'joinByArray',
withType: [
'person',
'organization'
],
filters: {
projection: {
_url: 1,
title: 1,
}
},
required: true
},
...
这很好用。
另一方面,我希望与作者建立反向关系,以便有一种获取其项目的方法。
module.exports = {
extend: 'apostrophe-pieces',
name: 'person',
label: 'Person',
pluralLabel: 'People',
addFields: [
{
name: '_projects',
reverseOf: '_author',
idsField: 'creatorIds',
type: 'joinByArrayReverse',
withType: 'project',
filters: {
projection: {
_url: 1,
title: 1,
}
},
},
...
这可以正常编译,但是在站点加载后立即抛出此错误:
Error: I think you forgot to set idField or idsField, or you set the wrong one (use idField for byOne, idsField for byArray)
那么处理这种情况的合适策略是什么?
答案 0 :(得分:1)
贡献很晚,但这恰好发生在我身上。可以通过首先将片类型为 joinbyOne,创建几个片,然后将联接切换为 joinByArray 来重现该问题。
当我这样做时,我发现了您突出显示的错误。我通过删除 reverseOf
字段
就你而言:
name: '_projects',
idsField: 'creatorIds',
type: 'joinByArrayReverse',
withType: 'project',
filters: {
projection: {
_url: 1,
title: 1,
}
},
在 documentation 中,它声明该字段是可选的,只要只有一个连接件类型。如果您有多个 person
块类型的联接,则此解决方案可能不起作用。我仍然不确定为什么删除它解决了问题,但它起作用了。