mirror of
https://github.com/Barelydead/strapi-plugin-populate-deep.git
synced 2025-06-21 00:00:02 -04:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7847cfcb1e | ||
|
1175a82011 | ||
|
3634208405 | ||
|
85a9a7ad61 | ||
|
94e7c70660 | ||
|
b1809e0e1c | ||
|
403a510e0e | ||
|
25ff082461 | ||
|
5bb823f3e5 | ||
|
b560e3a15d | ||
|
83ee0a4187 | ||
|
bcc4c4ebbf | ||
|
db3b314ced |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "strapi-plugin-populate-deep",
|
||||
"version": "1.0.1",
|
||||
"version": "3.0.1",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "strapi-plugin-populate-deep",
|
||||
"version": "1.0.1",
|
||||
"description": "This is the description of the plugin.",
|
||||
"version": "3.0.1",
|
||||
"description": "Strapi plugin that populates nested content.",
|
||||
"strapi": {
|
||||
"name": "strapi-plugin-populate-deep",
|
||||
"description": "Api helper to populate deep content structures.",
|
||||
@ -21,8 +21,8 @@
|
||||
"url": "https://github.com/Barelydead/strapi-plugin-deep-populate"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.x.x <=16.x.x",
|
||||
"node": ">=14.19.1 <=20.x.x",
|
||||
"npm": ">=6.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
2
server/bootstrap.js
vendored
2
server/bootstrap.js
vendored
@ -10,7 +10,7 @@ module.exports = ({ strapi }) => {
|
||||
|
||||
if (populate && populate[0] === 'deep') {
|
||||
const depth = populate[1] ?? defaultDepth
|
||||
const modelObject = getFullPopulateObject(event.model.uid, depth);
|
||||
const modelObject = getFullPopulateObject(event.model.uid, depth, []);
|
||||
event.params.populate = modelObject.populate
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
const { isEmpty, merge } = require("lodash/fp");
|
||||
|
||||
const skipCreatorFields = strapi.plugin('strapi-plugin-populate-deep')?.config('skipCreatorFields') || true;
|
||||
|
||||
const getModelPopulationAttributes = (model) => {
|
||||
if (model.uid === "plugin::upload.file") {
|
||||
const { related, ...attributes } = model.attributes;
|
||||
@ -11,7 +9,9 @@ const getModelPopulationAttributes = (model) => {
|
||||
return model.attributes;
|
||||
};
|
||||
|
||||
const getFullPopulateObject = (modelUid, maxDepth = 20) => {
|
||||
const getFullPopulateObject = (modelUid, maxDepth = 20, ignore) => {
|
||||
const skipCreatorFields = strapi.plugin('strapi-plugin-populate-deep')?.config('skipCreatorFields');
|
||||
|
||||
if (maxDepth <= 1) {
|
||||
return true;
|
||||
}
|
||||
@ -21,9 +21,11 @@ const getFullPopulateObject = (modelUid, maxDepth = 20) => {
|
||||
|
||||
const populate = {};
|
||||
const model = strapi.getModel(modelUid);
|
||||
if (ignore && !ignore.includes(model.collectionName)) ignore.push(model.collectionName)
|
||||
for (const [key, value] of Object.entries(
|
||||
getModelPopulationAttributes(model)
|
||||
)) {
|
||||
if (ignore?.includes(key)) continue
|
||||
if (value) {
|
||||
if (value.type === "component") {
|
||||
populate[key] = getFullPopulateObject(value.component, maxDepth - 1);
|
||||
@ -36,7 +38,8 @@ const getFullPopulateObject = (modelUid, maxDepth = 20) => {
|
||||
} else if (value.type === "relation") {
|
||||
const relationPopulate = getFullPopulateObject(
|
||||
value.target,
|
||||
(key === 'localizations') && maxDepth > 2 ? 1 : maxDepth - 1
|
||||
(key === 'localizations') && maxDepth > 2 ? 1 : maxDepth - 1,
|
||||
ignore
|
||||
);
|
||||
if (relationPopulate) {
|
||||
populate[key] = relationPopulate;
|
||||
|
Loading…
x
Reference in New Issue
Block a user