Sails.js offers a way to populate objects in Many to Many relationship via its Blueprint API. Thus, GET /categorymodel/:categoryid/productscollection
will return all products that belong to the specified category. Link.
For Many to Many Through relations, the docs advises to use multiple One to Many relations via an intermediary model to achieve the desired organization. The downside of this is there's no way to populate objects via the built-in Blueprint API. Link.
So, while querying for products belonging to a particular category, I query GET /categorymodel/:categoryid/intermediarycollection
to get something like
[{categoryid: 1, productid: 1, id: 1}, {categoryid: 1, productid: 2, id: 2}, {categoryid: 1, productid: 3, id: 3}, ... n]
This means the client will have to GET /products/:productid
n times.
How do I process the populate() result (and not edit/override it) to add the product object before sending to the client? Is there a better way of doing this?