diff --git a/README.md b/README.md index a2e74ba..8b3005d 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ module.exports = ({ env }) => ({ 'strapi-plugin-populate-deep': { config: { defaultDepth: 3, // Default is 5 + excludeLocalizations: true // do not include localizations for other languages in response if using i18n plugin } }, }); diff --git a/server/bootstrap.js b/server/bootstrap.js index cb357c6..ac57798 100644 --- a/server/bootstrap.js +++ b/server/bootstrap.js @@ -7,10 +7,15 @@ module.exports = ({ strapi }) => { if (event.action === 'beforeFindMany' || event.action === 'beforeFindOne') { const populate = event.params?.populate; const defaultDepth = strapi.plugin('strapi-plugin-populate-deep')?.config('defaultDepth') || 5 + const excludeLocalizations = strapi.plugin('strapi-plugin-populate-deep')?.config('excludeLocalizations') || false if (populate && populate[0] === 'deep') { const depth = populate[1] ?? defaultDepth - const modelObject = getFullPopulateObject(event.model.uid, depth, []); + const ignored = [] + if (excludeLocalizations) { + ignored.push('localizations') + } + const modelObject = getFullPopulateObject(event.model.uid, depth, ignored); event.params.populate = modelObject.populate } }