Context
I have a front end app that requires an array of blog posts from the API, and when you call http://strapi-url/posts/
with a GET request, it returns all the results as objects in an array. Happy days.
Problem
Eventually I want to have more complex GET options with query params, so I need to modify the post controller and write a custom function for find()
.
When I modify the find()
function in api/post/controllers/post.js
, and just make it return the result of strapi.query('post').find()
, it returns an object with keys rather than an array.
Code
async find(ctx) {
let entity = await.strapi.query('post').find();
return sanitizeEntity(entity, { model: strapi.models.post });
},
I know I could simply convert it into an array in the front end, but feels like a messy solution, and I would rather understand why it doesn't return an array, and what would be the best way to approach a solution.