Open tamias opened 6 years ago
It might be possible to accomplish something like this using rest-hapi, but it would be more of a hack since it is not part of the intended functionality.
However, keep in mind that rest-hapi is built on top of Mongoose, so you can still take advantage of populating docs directly.
Okay, thank you for the response!
A quick followup. The difficulty I'm running into is that if I want to call .populate()
myself, I can't use Rest-Hapi's handler helpers in that flow, because they all call .lean()
. The solution we went with for now is to call RestHapi.find()
, then retrieve the associated documents with a separate query and populate them manually.
It would be great if there were some way to specify an embed of 'subdoc.pets' that made populateEmbeddedDocs
call .populate({ path: 'subdoc.pets' })
instead of .populate({ path: 'subdoc', populate: { path: 'pets' } })
.
@tamias thanks for pointing this out. I agree! I think I'll add two more feature requests: one to have an option of disabling .lean()
and one for populating subdocs.
Populating subdocs would be a very important feature for an association. From the Swagger documentation it seems to be possible
but server returns 500 with this error
— Error: Association not found. [08:46:24.493] 5437 ERROR node_modules/rest-hapi/utilities/handler-helper.js:1677:9 api/user/GetAll — at nestPopulate (/home/fabrizio/Projects/gse-bip/gse-server/backend/node_modules/rest-hapi/utilities/query-helper.js:523:13) [08:46:24.493] 5437 ERROR node_modules/rest-hapi/utilities/handler-helper.js:1677:9 api/user/GetAll — at /home/fabrizio/Projects/gse-bip/gse-server/backend/node_modules/rest-hapi/utilities/query-helper.js:408:20 [08:46:24.493] 5437 ERROR node_modules/rest-hapi/utilities/handler-helper.js:1677:9 api/user/GetAll — at Array.forEach (<anonymous>) [08:46:24.493] 5437 ERROR node_modules/rest-hapi/utilities/handler-helper.js:1677:9 api/user/GetAll — at Object.populateEmbeddedDocs (/home/fabrizio/Projects/gse-bip/gse-server/backend/node_modules/rest-hapi/utilities/query-helper.js:404:20) [08:46:24.493] 5437 ERROR node_modules/rest-hapi/utilities/handler-helper.js:1677:9 api/user/GetAll — at Object.createMongooseQuery (/home/fabrizio/Projects/gse-bip/gse-server/backend/node_modules/rest-hapi/utilities/query-helper.js:88:23) [08:46:24.493] 5437 ERROR node_modules/rest-hapi/utilities/handler-helper.js:1677:9 api/user/GetAll — at _listHandler (/home/fabrizio/Projects/gse-bip/gse-server/backend/node_modules/rest-hapi/utilities/handler-helper.js:115:33)
It is a Mongoose feature, why is it not possibile with RestHapi?. Or am I wrong in something? Thanks!
(This is more of a question than an issue, but it could turn into an issue.)
Is it possible, in rest-hapi, to have an association within a subdocument?
For example, I can do this in Mongoose, where the association is at
subdoc.pets
, instead of being at the top level of the document:If it were at the top level, I would implement this in rest-hapi by adding an association under routeOptions. I'm not sure how or if I can do this within a subdocument, however.
I don't actually need endpoints for this particular association; I just need to be able to populate it when requesting the document, if that makes a difference.
Thanks!