loopback icon indicating copy to clipboard operation
loopback copied to clipboard

API operations don't accessible for two levels of embedded models

Open agregoris opened this issue 11 years ago • 7 comments

I have three models Guide, Translation and Step and they conform one single collection of documents like these:

{
  "guideName": "How to ...",
  "translations": [
    {
      "language": "en",
      "steps": [
        {
          "description": "Open a bottle of ..."
        }
      ] 
    }
  ]
}

I have three levels in my model but when I open the Loopback API explorer I find that the "Step" embedded model is not accessible by the API, I only have operations for "Guide" and "Translation" like these:

  • POST /guides Create a new instance of the model and persist it into the data source.
  • POST /guides/{id}/translations Creates a new instance in translations of this model.

But I don't have a method to post a step like this:

  • POST /guides/{id}/translations/{translationId}/steps Creates a new instance in steps of this model.

Why are not these operations exposed by default? How can I expose this kind of methods for embedded objects of embedded objects?

agregoris avatar Aug 13 '15 10:08 agregoris

I believe we do not support second level API operations yet. @raymondfeng Please confirm.

superkhau avatar Aug 13 '15 21:08 superkhau

You'll have to explicitly call Guide.nestRemoting() to allow that.

raymondfeng avatar Aug 13 '15 22:08 raymondfeng

Thank you very much. It's worked.

I have added a boot script with the sentence:

Guide.nestRemoting('translations');

and now the endpoints for the Step model are accesible from guides/{guideId}/translations/{translationId}/steps, although the endpoints are enabled these aren't visible in the StrongLoop API Explorer, is there any option to turn on them in the explorer?

agregoris avatar Aug 14 '15 09:08 agregoris

Did you set the public property on the model? See https://docs.strongloop.com/display/public/LB/Exposing+models+over+REST;jsessionid=DE93CB65560351A7D9555A2BE5F080A5

superkhau avatar Aug 14 '15 16:08 superkhau

If I set the public property of "translation" model the result is that the translations endpoint is showed like a new collection in the explorer not like a embedded collection inside "guides".

agregoris avatar Aug 17 '15 09:08 agregoris

@onnoll Are you still running into issues? Can I close this?

superkhau avatar Feb 03 '16 02:02 superkhau

Actually I'm closing this as resolved since the original problem has been answered. Please open a new issue if you are still running into problems.

superkhau avatar Feb 03 '16 02:02 superkhau