I'm having problems with getting data of the piece from nested join: joinByArray
– joinByOne
. I tried to use the projection filters in joins and to omit them – it does not work (in different ways, but the result is the same – no joined piece data).
Here is my setup. I have defined two pieces:
Author:
extend: 'apostrophe-pieces',
name: 'author',
// ...
addFields: [
{
name: 'photo',
label: 'Photo',
required: true,
type: 'singleton',
widgetType: 'apostrophe-images',
options: {
limit: [ 1 ]
}
},
// ...
Publication:
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
}
}
},
// ...
Then I created a Publications Page like this:
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: [
// ...
]
},
// ...
As you can see _featured
is the featured publications list those are supposed to be displayed on the top of the page followed by the list on other publications. I need all the data to display them correctly, including Author's name (title
) and photo.
The thing is that in Nunjucks template I got:
authorId
only if I use projection
for _featured
joinprojection
for _featured
joinThe general list of publications (available through data.pieces
in Nunjucks index.html
template) is PERFECT and contains all the data. While data.page._featured
does NOT.
MY QUESTION: is there a way to tell Apostrophe CMS to fetch data from nested joins like those above? So to get Author piece data for "featured" Publications on Publications Page?
I like this setup, and I'd prefer to keep it this way. But if I need to change something (e.g. use singleton
instead on joinByOne
), I may try it as well.
I think you want to add withJoins: true
to your _featured
join configuration