How do I return only selected certain fields in Strapi?

后端 未结 5 1580
独厮守ぢ
独厮守ぢ 2021-01-18 06:16

Pretty straightforward (I hope). I\'d like to be able to use the API endpoint and have it only return specified fields. I.E. something like this

http://local         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 07:06

    In the current strapi version (3.x, not sure about previous ones) this can be achieved using the select method in custom queries, regardless of which ORM is being used.

    SQL example:

     const restaurant = await strapi
        .query('restaurant')
        .model.query((qb) => {
            qb.where('id', 1);
            qb.select('name');
        })
        .fetch();
    

提交回复
热议问题