我是 P'unk Avenue 的 Apostrope 的建筑师。
您自己的解决方案中的代码有效地重新实现了我们已有的功能:反向连接。
您已经有一个“前向”连接(joinByOne
)。所以使用joinByOneReverse
使这些物品可以从“另一边”获得。
在架构中authors,你可以这样写:
addFields: [
{
name: '_articles',
type: 'joinByOneReverse',
withType: 'articles',
label: 'Articles',
idField: 'author',
filters: {
projection: {
title: 1,
slug: 1,
type: 1,
tags: 1
}
}
}
]
这使得._articles
每个作者都可用的数组属性。
重要的是要注意idField
没有改变。我们有意使用相同的信息,以便获得相同的内容。
如果您愿意,还可以设置ifOnlyOne: true
在该字段上,以避免为索引页和加载多个作者的其他上下文获取它。
查看模式指南 http://apostrophecms.org/docs/tutorials/getting-started/schema-guide.html了解更多信息。