From 69945fd9bb30366939418b5f5555005bc52c37a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Mon, 22 Aug 2022 10:54:58 +0200 Subject: [PATCH] handle populate: false --- .../core/database/lib/query/helpers/populate.js | 4 ++++ .../tests/api/populate/filtering/index.test.e2e.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/core/database/lib/query/helpers/populate.js b/packages/core/database/lib/query/helpers/populate.js index c5f01fabe2..4d45e56fd4 100644 --- a/packages/core/database/lib/query/helpers/populate.js +++ b/packages/core/database/lib/query/helpers/populate.js @@ -83,6 +83,10 @@ const processPopulate = (populate, ctx) => { continue; } + if (populateMap[key] === false) { + continue; + } + // make sure id is present for future populate queries if (_.has('id', meta.attributes)) { qb.addSelect('id'); diff --git a/packages/core/strapi/tests/api/populate/filtering/index.test.e2e.js b/packages/core/strapi/tests/api/populate/filtering/index.test.e2e.js index 434bbc381e..24931e882f 100644 --- a/packages/core/strapi/tests/api/populate/filtering/index.test.e2e.js +++ b/packages/core/strapi/tests/api/populate/filtering/index.test.e2e.js @@ -300,5 +300,19 @@ describe('Populate filters', () => { expect(body.data[0].attributes.third.data[0].attributes.fooRef).toBeUndefined(); }); + + test("Don't populate with object and 'f'", async () => { + const qs = { + populate: { + third: 'f', + }, + }; + const { status, body } = await rq.get(`/${schemas.contentTypes.c.pluralName}`, { qs }); + + expect(status).toBe(200); + expect(body.data).toHaveLength(2); + + expect(body.data[0].attributes.third).toBeUndefined(); + }); }); });