Strapi v4 select field in populated nested query

System Information
  • Strapi Version: 4.10.6
  • Operating System: Windows 11
  • Database: Sqlite
  • Node Version: 18.12.2
  • NPM Version: 9.2.0
  • Yarn Version: 1.22.19

I’m trying to query an entity from my database on a custom route.

Here is the query part of my code :

const allMakeupArtiste = await strapi.entityService.findMany(
        "api::makeup-artiste.makeup-artiste",
        {
          populate: {
            main_picture: {
              populate: "*",
            },
            skills: {
              populate: "*",
            },
            experiences: {
              populate: "*",
            },
            courses: {
              populate: "*",
            },
            service_offers: {
              populate: "*",
            },
            network: {
              populate: "*",
            },
            language: {
              populate: "*",
            },
            user: {
              select: ["username"],
            },
            image_gallery: {
              populate: "*",
            },
          },
          filters: {
            available: {
              $eq: true,
            },
          },
        }
      );

The strange part is : I’m selecting only the username field of the user, but the returned object is :

[
	{
		"id": 1,
		"last_name": "Lagrange",
		"first_name": "Milo",
		"speciality": "mains",
		"city": "Nantes",
		"action_radius": 25,
		"score": 4.7,
		"available": true,
		"description": "Je suis steph",
		"createdAt": "2023-05-06T17:23:27.214Z",
		"updatedAt": "2023-06-13T19:56:41.043Z",
		"main_picture": null,
		"skills": [
			{
				"id": 19,
				"name": "mains",
				"description": null
			},
			{
				"id": 20,
				"name": "les pieds",
				"description": null
			}
		],
		"experiences": [
			{
				"id": 26,
				"company": "Insti'art",
				"job_name": "Institue art",
				"city": "Paris",
				"date_start": "2018-04-11",
				"date_end": "2019-04-03",
				"description": "je coloriais les pieds avec ma langue"
			},
			{
				"id": 27,
				"company": "Insti'art2",
				"job_name": "Institue art 2",
				"city": "Paris",
				"date_start": "2018-04-11",
				"date_end": "2019-04-03",
				"description": "je coloriais les pieds avec ma langue"
			}
		],
		"courses": [
			{
				"id": 14,
				"diploma": "art et boté",
				"school": "diplomatica",
				"date_graduation": "2023-04-06",
				"course_description": "france"
			}
		],
		"service_offers": [
			{
				"id": 14,
				"name": "mains",
				"description": "je te colorie les mains en bleu comme shrek",
				"price": "69.0",
				"options": []
			}
		],
		"network": {
			"id": 14,
			"youtube": "twitter.com",
			"facebook": "youtube.com",
			"instagram": "youtube.com",
			"website": "youtube.com",
			"linkedin": null,
			"phone": null,
			"email": null
		},
		"language": [
			{
				"id": 27,
				"name": "Francais"
			},
			{
				"id": 28,
				"name": "Anglais"
			}
		],
		"user": {
			"id": 1,
			"username": "admin",
			"email": "amfr@grg.gr",
			"provider": "local",
			"password": "$2a$10$/0RB/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
			"resetPasswordToken": null,
			"confirmationToken": null,
			"confirmed": true,
			"blocked": false,
			"createdAt": "2023-05-06T17:22:58.458Z",
			"updatedAt": "2023-06-10T23:01:48.565Z"
		},
		"image_gallery": null,
	},
...]

I tried different way to write the select but it dont seem to work, have you an idea ?

I am not sure which other ways of trying to write select you tried, but as it shows here: Populating | Strapi Documentation

I believe you should use fields, instead of select. So it would be:

const allMakeupArtiste = await strapi.entityService.findMany(
        "api::makeup-artiste.makeup-artiste",
        {
          populate: {
            main_picture: {
              populate: "*",
            },
            skills: {
              populate: "*",
            },
            experiences: {
              populate: "*",
            },
            courses: {
              populate: "*",
            },
            service_offers: {
              populate: "*",
            },
            network: {
              populate: "*",
            },
            language: {
              populate: "*",
            },
            user: {
              fields: ["username"],
            },
            image_gallery: {
              populate: "*",
            },
          },
          filters: {
            available: {
              $eq: true,
            },
          },
        }
      );

I hope this helps :slight_smile:, I tested on a similar situation and it works properly for me that way, if I use select then all the fields appear like you described.