Query nested content in Single Types?

System Information
  • Strapi Version: 3.6.2
  • Operating System: Ubuntu 20.04
  • Database: MongoDB
  • Node Version: 14.7.3
  • NPM Version: 6.14.13
  • Yarn Version: 1.22.5

Hi. I’m building a blog with Strapi and I’m trying to query nested content in a single type, but I haven’t been able to figure out how to do it.

Here are the collection types involved:

  • Article - A simple blog article that has categories and a single author
  • Author - An author that belongs to the blog and can produce articles. An article has only one author.
  • Categories - Simple categories with only names.

The single type I was talking about is the main banner on the blog’s home page, which displays a custom selection of articles. Its only field is a one-to-many relation with the Article type. When finding this single type through the Content API, I’m currently only getting the ids for the entities that are related to the articles (author and categories), but I want to get extra fields such as the author’s name, each category’s name, etc. How can I do that?

Thanks in advance.

You’ll need to modify the services to customize the populate in the v3, with the upcoming v4 you’ll be able to dynamically populate at request time.

const results = await strapi.query('restaurant').find({ ...params, _limit: 1 }, populate);

That populate parameter is an array of relation fields and their nested relations so something like [ "author", "author.role" ] ect