Hello,
I try to update the title of a component from the title of a nested component, it works as expected if I refresh the page, however I would like this to be more dynamic and change the updated data on the fly.
module.exports = {
async afterUpdate(event) {
return await createTitleFromCategory(event);
},
};
async function createTitleFromCategory(event) {
const categoryPages = await strapi.entityService.findMany(
"api::category-page.category-page",
{
populate: [
"pages.category",
"pages.banners",
"pages.banners.image",
"pages.brands",
"pages.shelves",
"pages.shelves.products",
],
}
);
await Promise.all(
categoryPages.pages.map(async (page) => {
const categoryTitle = page.category.title;
if (page.title === categoryTitle) return;
await strapi.entityService.update(
"api::category-page.category-page",
categoryPages.id,
{
data: {
pages: categoryPages.pages.map((page) => {
return {
...page,
title: page.category.title,
};
}),
},
}
);
})
);
}
I have tried overwriting event.params.data.pages but the pages data have a specific format, which does not work.
[
{
id: 4,
__pivot: { field: 'pages', component_type: 'categories.page' }
},
{
id: 5,
__pivot: { field: 'pages', component_type: 'categories.page' }
}
]
This topic has been created from a Discord post (1228021137372610690) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord