How can i perform deep filtering from the components value?

This is my schema.json code :

{
  "kind": "collectionType",
  "collectionName": "user_planner_v2s",
  "info": {
    "singularName": "user-planner-v2",
    "pluralName": "user-planner-v2s",
    "displayName": "UserPlannerV2",
    "description": ""
  },
  "options": {
    "draftAndPublish": true
  },
  "pluginOptions": {},
  "attributes": {
    "planBlock": {
      "displayName": "planBlock",
      "type": "component",
      "repeatable": true,
      "component": "user-planner.plan-block"
    }
  }
}

and this is my planBlock component json structure :
{
“collectionName”: “components_user_planner_plan_blocks”,
“info”: {
“displayName”: “planBlock”,
“icon”: “collapse”
},
“options”: {},
“attributes”: {
“plans”: {
“type”: “component”,
“repeatable”: false,
“component”: “user-planner.plans”
},
“date”: {
“type”: “date”
}
}
}

I am trying to filter according to the date ,tried creating controller and filtering but it didn’t worked

   const programs = await strapi.entityService.findMany(
              "api::user-planner-v2.user-planner-v2",
              {
                filters: {
                  userCategory: {
                    $eq: user.category,
                  },
                  planBlock: {
                    date: {
                      $eq: date
                    }
                  }
                },
                populate: {
                  planBlock: {
                    populate: {
                      plans: {
                        populate: {
                          train_pages: {
                            populate: {
                              image: true,
                              equipment:true,
                              author: true
                            },
                          },
                          eat_detail_pages: {
                            populate: {
                              image: true,
                              chef:true
                            },
                          },
                          meditation_pages: {
                            populate: {
                              image: true,
                              author: true
                            },
                          },
                        },
                      },
                    },
                  },
                  headers: true,
                },
              }
            );

Please give me any suggestion what can I do . I cannot bring the date field out from the planBlock and it also it is repeatable component .
Thankyou

Get in mind that you can use filters while populating the repeatable components.

Your solution will like this after adding the filters while populating your repeatable components.

// your existing code

populate: {
                planBlock: {
                  filters: {                        // add filters for repeateable component here while populating
                    date: date,  
                  },
                  populate: {
                    plans: {
                      populate: {
                        train_pages: {
                          populate: {
                            image: true,
                            equipment: true,
                            author: true,
                          },

// Your remaining code

For more reference on advanced populating: https://docs.strapi.io/dev-docs/api/entity-service/populate#advanced-populating

1 Like

thanks a lot it is working

1 Like