How to populate component that comes from a deep nested relation

System Information
  • Strapi Version: 3.4.2
  • Operating System: Windows 10 Pro - 20H2
  • Database: MySql
  • Node Version: 12.19.0
  • NPM Version: 6.14.9
  • Yarn Version: 1.22.5

I have the following code:

find(params, populate) {
return strapi
  .query("menu")
  .find(params, [
    "categories",
    "categories.plates",
    "categories.plates.image",
    "categories.subcategories",
    "categories.subcategories.plates",
    "categories.subcategories.plates.image",
  ]);
},

in which categories, subcategories and plates are all models.

And plates also has a repeatable component called variants:

"variants": {
  "type": "component",
  "repeatable": true,
  "component": "menu.options"
},

I tried putting categories.plates.variants in the find and findOne methods and it didn’t work. Am I missing something? I know there’s a lot of nested stuff in it and I’m open to suggestions.

Thanks

Hi @Rendon

Were you able to find a solution here? I’m also unable to populate some relation fields in a component. Just getting an array of IDs.

Hi Ajisilva :wave:,

I’ve added the following code to the controller of “products”. The code will populate the relation field “category” and the deep nested relation “gender” which is attached to “category”. Should work with Mongoose as a database.

async find(ctx) {
return strapi
  .query("products")
  .find(ctx.query, [
    {
      path: "category",
      populate: {
        path: "gender"
      }
    }
  ]);
}

Good luck!

Thanks @devwearsprada,

I’ve tried something similar to this, but it did not work. In my case, I am trying to populate a relation inside a component that is being used in a dynamic zone.

For reference, here’s my schema and the code I’ve tried:

    await strapi.query("home").model.find().populate({
      path: "content",
      populate: {
        path: "activity_series",
        populate: {
          path: "activities"
        }
      }
    });

The query above will throw this mongoose error:
MissingSchemaError: Schema hasn't been registered for model "home".

As a workaround, I am just making a second query with the IDs that are being returned and it works fine. But, it would be awesome to find a solve to this. Thanks!

Hi, has anybody found a simple solution to this issue that’s not a workaround?