mirror of
https://github.com/strapi/strapi.git
synced 2025-12-11 15:04:33 +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';
|
'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 strapiUtils = require('@strapi/utils');
|
||||||
const { ApplicationError } = require('@strapi/utils').errors;
|
const { ApplicationError } = require('@strapi/utils').errors;
|
||||||
|
|
||||||
@ -40,15 +40,11 @@ const findCreatorRoles = entity => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: define when we use this one vs basic populate
|
// TODO: define when we use this one vs basic populate
|
||||||
const getDeepPopulate = (uid, populate, depth = 0) => {
|
const getDeepPopulate = (uid, populate) => {
|
||||||
if (populate) {
|
if (populate) {
|
||||||
return populate;
|
return populate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (depth > 2) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
const { attributes } = strapi.getModel(uid);
|
const { attributes } = strapi.getModel(uid);
|
||||||
|
|
||||||
return Object.keys(attributes).reduce((populateAcc, attributeName) => {
|
return Object.keys(attributes).reduce((populateAcc, attributeName) => {
|
||||||
@ -60,7 +56,7 @@ const getDeepPopulate = (uid, populate, depth = 0) => {
|
|||||||
|
|
||||||
if (attribute.type === 'component') {
|
if (attribute.type === 'component') {
|
||||||
populateAcc[attributeName] = {
|
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') {
|
if (attribute.type === 'dynamiczone') {
|
||||||
populateAcc[attributeName] = {
|
populateAcc[attributeName] = {
|
||||||
populate: (attribute.components || []).reduce((acc, componentUID) => {
|
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