this is a partial continuation of the following question: How to show pieces into the another pieces? and another one that I accidentally deleted, but got a lot of help on (thanks!)
I have the following module blogTag that I want to connect via the joinByOneReverse field with pieces of the apostrophe blog module and pieces created by me "work" and "inspiration". It´s here index.js:
module.exports = {
extend: 'apostrophe-pieces',
name: 'blogTag',
label: 'Blog Tag',
pluralLabel: 'Blog Tags',
addFields: [
{
name: 'title',
label: 'Title',
type: 'string',
required: true
},
{
name: 'intro',
label: 'Introduction',
type: 'area',
options: {
widgets: {
'apostrophe-rich-text': {
controls: ['Bold', 'Italic', 'Link', 'Unlink']
},
'apostrophe-images': {}
}
}
},
{
name: 'icon',
label: 'Icon',
type: 'singleton',
widgetType: 'apostrophe-images',
options: {
limit: 1
}
},
{
name: '_workName',
type: 'joinByOneReverse',
withType: 'work',
label: 'Work',
idField: 'blogTagId',
filters: {
projection: {
title: 1,
slug: 1,
type: 1,
tags: 1
}
}
},
{
name: '_inspirationName',
type: 'joinByOneReverse',
withType: 'inspiration',
label: 'Inspiration',
idField: 'blogTagInspirationId',
filters: {
projection: {
title: 1,
slug: 1,
type: 1,
tags: 1
}
}
},
{
name: '_blogTagArticleName',
type: 'joinByOneReverse',
withType: 'apostrophe-blog',
label: 'Blog Article',
idField: 'blogTagArticleId',
filters: {
projection: {
title: 1,
slug: 1,
type: 1,
tags: 1
}
}
}
]
}
and as an example for the "work" piece I have the following module with the following index.js module in a "b2b-portfolio" folder:
module.exports = {
extend: 'apostrophe-pieces',
name: 'work',
label: 'Work',
pluralLabel: 'Works',
addFields: [
{
name: 'title',
label: 'Title',
type: 'string',
required: true
},
{
name: 'intro',
label: 'Introduction',
type: 'area',
options: {
widgets: {
'apostrophe-rich-text': {
controls: ['Bold', 'Italic', 'Link', 'Unlink']
},
'apostrophe-images': {}
}
}
},
{
name: 'screenshot',
label: 'Screenshot',
type: 'singleton',
widgetType: 'apostrophe-images',
options: {
limit: 1,
minSize: [ 800, 800 ],
aspectRatio: [ 1, 1]
}
},
{
name: '_blogTag',
type: 'joinByOne',
withType: 'blogTag',
label: 'Blog Tag',
idField: 'blogTagId',
filters: {
projection: {
title: 1,
slug: 1,
type: 1,
tags: 1
}
}
},
{
name: 'publishedAt',
label: 'Publishing date',
type: 'date'
}
]
}
However, in the module "b2b-blog-tags-pages" the following in show.html views does not output the expected data:
{% for work in data._workName %}
<h2><a href="{{ work._url }}">{{ work.title }}</a></h2>
{% endfor %}
What am I missing or doing wrong here?
EDIT: The following did not work either:
{% for work in data.piece._workName %}
<h2><a href="{{ work._url }}">{{ work.title }}</a></h2>
{% endfor %}
Here are the MongoDB documents from the aposDocs collection as an example:
and..

