From be6e10e04c4b6545ccd44b6c80766431bc2bf0e2 Mon Sep 17 00:00:00 2001 From: tooonuch Date: Mon, 14 Oct 2024 18:25:57 +0200 Subject: [PATCH] fix issue with population of fields with the same names --- server/helpers/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/helpers/index.js b/server/helpers/index.js index 0bcbf63..2e3d48f 100644 --- a/server/helpers/index.js +++ b/server/helpers/index.js @@ -11,8 +11,8 @@ const getModelPopulationAttributes = (model) => { const getFullPopulateObject = (modelUid, maxDepth = 20, ignore) => { const skipCreatorFields = strapi - .plugin("strapi-plugin-populate-deep") - ?.config("skipCreatorFields"); + .plugin("strapi-plugin-populate-deep") + ?.config("skipCreatorFields"); if (maxDepth <= 1) { return true; @@ -26,7 +26,7 @@ const getFullPopulateObject = (modelUid, maxDepth = 20, ignore) => { if (ignore && !ignore.includes(model.collectionName)) ignore.push(model.collectionName); for (const [key, value] of Object.entries( - getModelPopulationAttributes(model) + getModelPopulationAttributes(model) )) { if (ignore?.includes(key)) continue; if (value) { @@ -35,14 +35,14 @@ const getFullPopulateObject = (modelUid, maxDepth = 20, ignore) => { } else if (value.type === "dynamiczone") { const dynamicPopulate = value.components.reduce((prev, cur) => { const curPopulate = getFullPopulateObject(cur, maxDepth - 1); - return curPopulate === true ? prev : merge(prev, curPopulate); + return merge(prev, {[cur]: curPopulate}); }, {}); - populate[key] = isEmpty(dynamicPopulate) ? true : dynamicPopulate; + populate[key] = isEmpty(dynamicPopulate) ? true : { on: dynamicPopulate }; } else if (value.type === "relation") { const relationPopulate = getFullPopulateObject( - value.target, - key === "localizations" && maxDepth > 2 ? 1 : maxDepth - 1, - ignore + value.target, + key === "localizations" && maxDepth > 2 ? 1 : maxDepth - 1, + ignore ); if (relationPopulate) { populate[key] = relationPopulate;