Can I have select inside of populate?

System Information
  • Strapi Version: 4.1.7
  • Operating System: Windows
  • Database: SQLite
  • Node Version: 16.14.2
  • NPM Version: 8.5.0
  • Yarn Version: 1.22.18

I have two tables: user, and time-availability. Users can either be a mentee or a mentor. If he is a mentor, then he may have many time-availability. I’m just trying to display all time-availability records whose relation with user is symbolized by mentorId, but I only want the user’s first name, and last name. Here’s what I have so far:

strapi.db.query('api::time-availability.time-availability').findMany({
    populate: {
        mentorId: true,
        select: ['firstName', 'lastName']
    }
});

However, the query above also returns all of the fields related to the user table. How should I modify the query to get my expected behavior?

P.S. It’s my first time posting here, sorry if there are some standards I wasn’t able to follow.

Turns out, I just had to nest it like so:

strapi.db.query('api::time-availability.time-availability').findMany({
    populate: {
        mentorId: {
            select: ['firstName', 'lastName']
        }
    }
});
1 Like