I have a collection of headers - a header for each tenant that I'll be hosting. It has a title, and an array of navItems, which are relationships to the Pages collection. I have links in my header.
I also have a collection of footers - the footer for each tenant. The footer has an array of relationships to the footerSections collection, and a footerSection is a text heading and an array of navItems, in the same manner as the header. The footerSection collection exists to get around a name length limitation in postgresql.
If I search for a footer by the tenant slug, the result has a list of of sections, which have a list of navItems that are not populated - the references look like this:
"navItems": [
{
"id": "6766529f56f67c7324e89a76",
"link": {
"type": "reference",
"newTab": null,
"reference": {
"relationTo": "pages",
"value": 3
},
"url": null,
"label": "Legal Blurb"
}
}
],
navItems -> link -> reference -> should be populated. Depth is set far enough that it's not the issue.
I'm using the Local API. Is this an array population bug?
Collections:
Footer:
export const Footers: CollectionConfig = {
slug: 'footers',
access: {
create: isSuperAdmin,
delete: isSuperAdmin,
read: () => true,
update: canMutatePage,
},
admin: {
baseListFilter,
useAsTitle: 'title',
},
fields: [
{
name: 'title',
type: 'text',
hidden: true
},
{
name: 'sections',
label: 'Footer Sections',
type: 'array',
fields: [
{
name: 'section',
type: 'relationship',
relationTo: 'footerSection',
required: true
}
],
maxRows: 6
},
tenantField
],
}
FooterSection:
export const FooterSection: CollectionConfig = {
slug: 'footerSection',
access: {
create: isSuperAdmin,
delete: isSuperAdmin,
read: () => true,
update: canMutatePage,
},
admin: {
baseListFilter,
useAsTitle: 'header',
},
fields: [
{
name: 'header',
type: 'text',
label: 'Header (optional)',
required: false,
},
{
name: 'navItems',
type: 'array',
fields: [link({ appearances: false })],
maxRows: 10,
},
tenantField
],
}
The link field is grabbed from the website example.
in your link field can you open it up and show me the code for
const linkTypes: Field[] = [
there was a bug fix relating to this a while ago, you may have an old version and i wanna confirm
const linkTypes: Field[] = [
{
name: 'reference',
type: 'relationship',
admin: {
condition: (_, siblingData) => siblingData?.type === 'reference',
},
label: 'Document to link to',
maxDepth: 1,
relationTo: ['pages'],
required: true,
},
{
name: 'url',
type: 'text',
admin: {
condition: (_, siblingData) => siblingData?.type === 'custom',
},
label: 'Custom URL',
required: true,
},
]
if (!disableLabel) {
linkTypes.map((linkType) => ({
...linkType,
admin: {
...linkType.admin,
width: '50%',
},
}))
linkResult.fields.push({
type: 'row',
fields: [
...linkTypes,
{
name: 'label',
type: 'text',
admin: {
width: '50%',
},
label: 'Label',
required: true,
},
],
})
} else {
linkResult.fields = [...linkResult.fields, ...linkTypes]
}
if (appearances !== false) {
let appearanceOptionsToUse = [appearanceOptions.default, appearanceOptions.outline]
if (appearances) {
appearanceOptionsToUse = appearances.map((appearance) => appearanceOptions[appearance])
}
linkResult.fields.push({
name: 'appearance',
type: 'select',
admin: {
description: 'Choose how the link should be rendered.',
},
defaultValue: 'default',
options: appearanceOptionsToUse,
})
}
return deepMerge(linkResult, overrides)
}
remove
maxDepth: 1,
line
then try again
huh.
I was looking for a diff visually bvetween them and I missed that. Thank you.
maxDepth on a field won't take into consideration existing depth
so in a deeper reference it wont populate
I will check that, as soon as I get out of the meetings for the day.
so its not
currentDepth + 1
its always a hard limit, better removed
and using
defaultPopulate
for those collections to only get the data you need like title/slug etc
I think I'd figured out that I wanted to do that, also.
But that was lower on the list than solving this.
So, again, thank you.
Hm. Either I've done something wrong ... or this did not actually fix it.
This might well be me not successfully understanding the returned data in code, now. It looks complete.
Yep. Confirmed. I was putting the wrong information in to the CMSLink.
This was solved by separating in to more simple components, which enforced type safety.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.