I am trying to set up API end points like:
I am able to set up /workspaces and /workspaces/1/projects within my workspace.json config file.
I am able to get /workspaces/1/projects/1/sections to work using nestRemoting:
module.exports = (app) => {
app.models.Workspace.nestRemoting('projects');
app.models.Project.nestRemoting('sections');
app.models.Section.nestRemoting('questions');
};
However, /workspaces/1/projects/1/sections/1/questions does not work (although /projects/1/sections/1/questions does)
This issue was previously raised by @A11oW in this issue https://github.com/strongloop/loopback/issues/1853 (but the issue had already been closed).
Is there anyway to nest more than 3 levels? The docs suggest it's possible but do not show any examples.
A related but separate question...
Having read a load of issues on this:
My question is: Are there any plans to address the issues with Loopback that seem to prevent infinite nesting that works in a consistent way?
Hey @PaddyMann, I'm not quite sure why this doesn't work. We will have to dig a little further into the issue.
here is a possible workaround for this issue https://github.com/strongloop/loopback/issues/1859#issuecomment-163037446
related https://github.com/strongloop/loopback/issues/1865, https://github.com/strongloop/loopback/issues/1866
The above workaround is not ideal... (but is better than nothing, thanks @davidcheung)
Thanks @richardpringle , @davidcheung
I'm not sure if the above workaround would work here.
For example, if I was to add a remote route to Workspace with the path /workspaces/:workspaceId/projects/:projectId/sections/:sectionId/questions, then I'd have write a custom function that gets questions that meets the other criteria.
This would work if it was an issue I was only facing in one place, but that's not the case. And if I was to try and make the code reusable for other routes, I'd end up rewriting most of the ORM functionality which would seem a little crazy :)
But maybe I've missed something in what you're suggesting...
This looks like a limitation of the current implementation of nestRemoting to me, thus the feature label is more appropriate than bug.
With regards to the feature, the ideal solution would be one that provides a consistent set of functionality at any level.
Thus, I would want to be define that:
workspaces hasMany projects
projects hasMany sections
sections hasMany questions
If I then call the URL: /workspaces/:workspaceId/projects/:projectId/sections/:sectionId/questions it should be able to create a single database query that INNER JOINS the other tables. Though even better would be the ability to have more control over the type of join etc.
Hello @PaddyMann how did you solve this issue?
I facing a similar issue. I want to build the following endpoint
However with nestingRemote() I'm only able to get to the
and can't go to the deeper levels such as:
Is there any workaround to achieve this?
Hej @AndreMaz
We've initially tried to reduce the number of levels involved, trying to keep it to two. The downside is you need to have additional logic in your role-resolver to handle the parent levels. Currently only a fraction of our API has been moved over so I'm not 100% certain this will be the long term solution.
I've also hit a number of Loopback limitations that have led us to overide the default remote methods for the majority of routes - e.g.:
(so one option would be to go the whole hog and disregard the magic routes such as __get__rooms, instead handcranking them all)
Thanks @PaddyMann
This limitation is a huge drawback and kinda reduces the utility of the whole framework. Instead of just worrying about the data model where (supposedly) the rest of the logic were done by the framework we now have to keep in mind that only two levels are supported and use workarounds to go further...
@bajtos @pthieu @davidcheung @richardpringle is there any prediction about when (and if) this issue will be solved?
@AndreMaz I'm afraid i dont have a ETA on this feature, I will unassign myself for now as I won't have the bandwidth to work on this issue. If anyone can open a PR and give it a try would be great
__findbyid__books__pages regexfk/nk to be dynamic in the remoting options to avoid conflict, maybe like pageId, BookIdcc @bajtos @pthieu
Hi. Reading above, this seems like exact issue I'm having. I need support for more than 3 level child models e.g:
api/first/:id/second/:id/third/:id/fourth/:id
Is there any plan to integrate this and what are the timeframes? It seems there was no progress on this for a while. I'm sure there's a lot of people that are after this.
Is there any workaround for this??
Thanks
LoopBack version 3 is in LTS, we won't be adding any new features.
Most helpful comment
Thanks @PaddyMann
This limitation is a huge drawback and kinda reduces the utility of the whole framework. Instead of just worrying about the data model where (supposedly) the rest of the logic were done by the framework we now have to keep in mind that only two levels are supported and use workarounds to go further...
@bajtos @pthieu @davidcheung @richardpringle is there any prediction about when (and if) this issue will be solved?