mirror of
https://github.com/strapi/strapi.git
synced 2025-12-10 14:34:22 +00:00
Merge pull request #13331 from strapi/fix/deep-populate-components
Remove limit on deep populate on components
This commit is contained in:
commit
c006f74a4e
@ -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;
|
||||
|
||||
@ -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) => {
|
||||
@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
@ -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));
|
||||
}, {}),
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user