Polymorphic relations
It seems as though lb-ng is having trouble with polymorphic relations. It echoes:
Warning: scope Picture.imageable is missing _targetClass property. The Angular code for this scope won't be generated. Please upgrade to the latest version of loopback-datasource-juggler to fix the problem.
Updating loopback-datasource-juggler does not fix the problem, incidentally.
I am not familiar with polymorphic relations, could you please provide an example to reproduce the problem on my machine?
Absolutely. You can try this example from the Loopback documentation:
http://docs.strongloop.com/display/public/LB/Polymorphic+relations
Has there been any insight into this issue @bajtos? I would hate to see it get cleaned up in the triage.
@trolleycrash I am afraid my time is very limited and I can't afford building a full runnable example myself. Could you please fork loopback-sandbox and use it to build a runnable app that I can use to reproduce the issue?
Yes, of course, my apologies. I'm happy to do that. Thanks for the direction.
https://github.com/trolleycrash/loopback-angular-sdk-polymorphic-issue
Thank you for the example, I was able to reproduce the issue on my machine.
Here is the problem: Picture.imageable can point either to an Author or a Reader, this depends on the value of the "discriminator" property. In order to support polymorphic belongsTo relations in the Angular SDK, we would have to create a proxy-like resources returning different resource class depending on the request arguments. I guess it's doable, but definitely not trivial.
Is this something you need in your client application? Or are you just trying to get rid of the warning?
I see. The error doesn't present itself without the belongsTo relation defined. So polymorphic belongTo relations are out for the short term.
Thanks for pointing that out. If should probably be noted in the documnentation, is there somewhere more appropriate I can file that recommendation?
I suppose in the short term I don't need to have that relation expressed. I can add a custom method to the affected models where I need special functionality as well. You can safely mark this low-prority, from my perspective at least.
Thanks for your help. It's most appreciated!
Thanks for pointing that out. If should probably be noted in the documnentation, is there somewhere more appropriate I can file that recommendation?
I have updated the documentation myself: http://docs.strongloop.com/display/LB/AngularJS+JavaScript+SDK#AngularJSJavaScriptSDK-Workingwithrelatedmodels
/cc @crandmck
Thanks, I made some small edits to your addition.
When I try to call SDK generated method for hasMany relations example Worker.skills() I get a 404 not found error
I initially thought that its something to do with my ACLs but the api in explorer works alright /api/Worker/id/skills returns me a list of skills for a worker
Now i was trying to search for alternate means to query relations and found an example in loopback-getting-started-intermediate , in the example there is a way to query belongsTo relation but doesnt show how to query hasMany this is what is there in the example
$scope.reviews = Review.find({ filter: { where: { publisherId: $rootScope.currentUser.id }, include: [ 'coffeeShop', 'reviewer' ] } });
Can u please tell me if I am doing something incorrectly ?
@LetsDoIt- please post your question to our mailing list, see the Wiki for bug reporting guidelines.
Sorry for posting it at a wrong place, Done thanks