mirror of
https://github.com/strapi/strapi.git
synced 2025-11-24 22:21:38 +00:00
Handle components & relations for populate & deep populate filtering
This commit is contained in:
parent
5fb855227a
commit
51e1f762c1
@ -150,14 +150,43 @@ const convertPopulateQueryParams = (populate, schema, depth = 0) => {
|
|||||||
|
|
||||||
if (_.isPlainObject(populate)) {
|
if (_.isPlainObject(populate)) {
|
||||||
const transformedPopulate = {};
|
const transformedPopulate = {};
|
||||||
|
|
||||||
for (const key in populate) {
|
for (const key in populate) {
|
||||||
const targetSchema = strapi.getModel(attributes[key].target);
|
const attribute = attributes[key];
|
||||||
|
const subPopulate = populate[key];
|
||||||
|
|
||||||
|
if (!attribute) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve the target schema UID.
|
||||||
|
// This flows only handle basic relations and component since it's
|
||||||
|
// not possible to populate with params for a dynamic zone or polymorphic relations.
|
||||||
|
|
||||||
|
let targetSchemaUID;
|
||||||
|
|
||||||
|
// Relations
|
||||||
|
if (attribute.type === 'relation') {
|
||||||
|
targetSchemaUID = attribute.target;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Components
|
||||||
|
else if (attribute.type === 'component') {
|
||||||
|
targetSchemaUID = attribute.component;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback
|
||||||
|
else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetSchema = strapi.getModel(targetSchemaUID);
|
||||||
|
|
||||||
if (!targetSchema) {
|
if (!targetSchema) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
transformedPopulate[key] = convertNestedPopulate(populate[key], targetSchema);
|
transformedPopulate[key] = convertNestedPopulate(subPopulate, targetSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
return transformedPopulate;
|
return transformedPopulate;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user