Skip to content

Commit

Permalink
Merge pull request #13331 from strapi/fix/deep-populate-components
Browse files Browse the repository at this point in the history
Remove limit on deep populate on components
  • Loading branch information
alexandrebodin committed May 31, 2022
2 parents 4abd4fe + 2982fa7 commit c006f74
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/core/content-manager/server/services/entity-manager.js
@@ -1,6 +1,6 @@
'use strict';

const { assoc, has, prop, omit } = require('lodash/fp');
const { assoc, has, prop, omit, merge } = require('lodash/fp');
const strapiUtils = require('@strapi/utils');
const { ApplicationError } = require('@strapi/utils').errors;

Expand Down Expand Up @@ -40,15 +40,11 @@ const findCreatorRoles = entity => {
};

// TODO: define when we use this one vs basic populate
const getDeepPopulate = (uid, populate, depth = 0) => {
const getDeepPopulate = (uid, populate) => {
if (populate) {
return populate;
}

if (depth > 2) {
return {};
}

const { attributes } = strapi.getModel(uid);

return Object.keys(attributes).reduce((populateAcc, attributeName) => {
Expand All @@ -60,7 +56,7 @@ const getDeepPopulate = (uid, populate, depth = 0) => {

if (attribute.type === 'component') {
populateAcc[attributeName] = {
populate: getDeepPopulate(attribute.component, null, depth + 1),
populate: getDeepPopulate(attribute.component, null),
};
}

Expand All @@ -71,7 +67,7 @@ const getDeepPopulate = (uid, populate, depth = 0) => {
if (attribute.type === 'dynamiczone') {
populateAcc[attributeName] = {
populate: (attribute.components || []).reduce((acc, componentUID) => {
return Object.assign(acc, getDeepPopulate(componentUID, null, depth + 1));
return merge(acc, getDeepPopulate(componentUID, null));
}, {}),
};
}
Expand Down

0 comments on commit c006f74

Please sign in to comment.