When I use findOne().include('related-model') I get back a model that has the __data and __cachedRelationships properties. Currently I am using lodash to merge these into the complete fieldset. It seems weird to always have to doctor up the query results though.
Should __cachedRelations be included in toObject() and toJSON()? I don't know if this would go against current expectations, but it seems to make sense to me. I think it would make the API more convenient.
If not, then we should document how the application programmer is supposed to obtain that information. The current examples don't mention what you should do with the result set, and it's really not obvious from the implementation.
BTW, what is the proper way to get the embedded records? I am using __cachedRelations which seems to work. It returns an object with an array of related records.
Use toJSON()
toJSON isn't working for me... The relationship data is present in __cachedRelationships but does not get included in toJSON(). @raymondfeng I'm not sure how this code could be including the relationships, since it doesn't make any mention of them.
+1 this still doesn't appear to work. @bitmage I agree with you there is no mention of __cachedRelationships.
+1 toJSON is not a function on the model returned from an Model.findById
thanks!
Include filter https://loopback.io/doc/en/lb3/Include-filter.html + toJSON() worked for me
Most helpful comment
+1 this still doesn't appear to work. @bitmage I agree with you there is no mention of __cachedRelationships.