handle populate: false

This commit is contained in:
Pierre Noël 2022-08-22 10:54:58 +02:00
parent 0ab458fe0d
commit 69945fd9bb
2 changed files with 18 additions and 0 deletions

View File

@ -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');

View File

@ -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();
});
});
});