Skip to content

Commit 006d850

Browse files
Merge pull request #2 from matiasvlevi/main
add `customIgnored`
2 parents f03021a + 5ceb5ae commit 006d850

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Unleash the full potential of your Strapi content with nested, customizable popu
2626

2727
`/api/pages?customPopulate=nested&customDepth=4`
2828

29+
- Ignore custom properties
30+
31+
`/api/pages?customPopulate=nested&customIgnored[]=images&customIgnored[]=videos`
32+
2933
## Good to know
3034

3135
- Default maximum depth: 6 levels

main/configuration/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module.exports = {
44
default: {
55
defaultDepth: 6,
6+
ignore: [],
67
skipCreatorFields: true,
78
},
89
validator: () => { },

main/framework.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ module.exports = ({ strapi }) => {
99

1010
// Only proceed for 'beforeFindMany' or 'beforeFindOne' actions.
1111
if (action === 'beforeFindMany' || action === 'beforeFindOne') {
12-
const { customPopulate, customDepth } = params || {};
12+
const { customPopulate, customDepth, customIgnored } = params || {};
1313

1414
// Get the default depth from plugin config, fallback to 5 if undefined.
1515
const defaultDepth = strapi
1616
.plugin('strapi-plugin-nested-populator')
1717
?.config('defaultDepth') || 5;
1818

19+
// Get the default ignored list from plugin config, fallback to empty array if undefined.
20+
const defaultIgnored = strapi
21+
.plugin('strapi-plugin-nested-populator')
22+
?.config('ignore') || [];
23+
1924
// Apply population logic if 'nested' population is requested.
2025
if (customPopulate === 'nested') {
2126
const depth = customDepth > 0 ? customDepth : defaultDepth;
22-
const modelObject = buildPopulateTree(model.uid, depth, []);
27+
const ignored = customIgnored || defaultIgnored;
28+
const modelObject = buildPopulateTree(model.uid, depth, ignored);
2329

2430
// Update the event params with the computed population object.
2531
params.populate = modelObject.populate;

0 commit comments

Comments
 (0)