System Information
- Strapi Version: 3.2.5
- Operating System: ubuntu 18.04
- Database: postgresql
- Node Version: 12.18.3
- NPM Version: 6.14.3
- Yarn Version: -
I have a home-page model
home-page
-message
-images
-categoryA
-categoryB
“home-page”->model has many [“categoryA”,“categoryB”] relations
/home-page → gives all the data which is present,
but i need only specific fields from the model and its relations
typical response would look like this.
{
"message":"hello",
"categoryA":{
name:"abc",
image:"/uploads.."
},
"categoryB":{
name:"xyz",
image:"/uploads..."
}
}
this post How do I return only selected certain fields in Strapi? - Stack Overflow solves half of my problem but i am not aware how to use populate option with this approach to access specific fields from relations.
module.exports = {
findPaths: async ctx => {
const result = await strapi
.query('home-page')
.model.fetchAll({ columns: ['message'] }) // here we wait for one column only
ctx.send(result);
}
}