System Information
- Strapi Version: v3.1.4
- Operating System: Mac OS Catalina 10.15.7
- Database: MongoDB
- Node Version: v12.17.0
- NPM Version: 6.14.4
- Yarn Version: 1.22.5
Hi There,
I have a simple content-type “Onts”. “Onts” has a few relationships to other content-type, for example, “address_unit” or “services”. See screenshot below.
When I run a search query with Postman or the built-in Swagger platform, I successfully retrieve search results from any fields within the “Onts” document, however, I am unable to search within the relational documents.
See screenshots above.
Third Screenshot shows that I have success in searching for “5A594F43806616F8”.
However, with Fourth screenshot, I am trying to search “106” (which is the “unit_no” in “address_unit”) but with no success.
I have also tried searching for “5f01f63a408c5c5d59a04037” (which is the “vlan” in “services”) with no success.
I understand I will need to build a custom controller and services function in Strapi.
This is my current “/api/onts/services/onts.js” file:
module.exports = {
search: async (params) => {
return strapi.query("onts").search(params);
},
};
and this is my /api/onts/controllers/onts.js" file:
module.exports = {
async find(ctx) {
let entities;
if (ctx.query._q) {
entities = await strapi.services.onts.search(ctx.query);
} else {
entities = await strapi.services.onts.find(ctx.query);
}
return entities.map((entity) =>
sanitizeEntity(entity, { model: strapi.models.onts })
);
},
};
How do I go about in modifying the code to be able to search in relational documents as well?
Any assistance is appreciated.
Warm Regards,