loopback-sdk-angular-cli icon indicating copy to clipboard operation
loopback-sdk-angular-cli copied to clipboard

Polymorphic relations

Open trolleycrash opened this issue 11 years ago • 12 comments

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.

trolleycrash avatar Dec 18 '14 00:12 trolleycrash

I am not familiar with polymorphic relations, could you please provide an example to reproduce the problem on my machine?

bajtos avatar Dec 18 '14 08:12 bajtos

Absolutely. You can try this example from the Loopback documentation:

http://docs.strongloop.com/display/public/LB/Polymorphic+relations

trolleycrash avatar Dec 19 '14 15:12 trolleycrash

Has there been any insight into this issue @bajtos? I would hate to see it get cleaned up in the triage.

trolleycrash avatar Feb 12 '15 14:02 trolleycrash

@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?

bajtos avatar Feb 18 '15 14:02 bajtos

Yes, of course, my apologies. I'm happy to do that. Thanks for the direction.

https://github.com/trolleycrash/loopback-angular-sdk-polymorphic-issue

trolleycrash avatar Feb 18 '15 15:02 trolleycrash

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?

bajtos avatar Feb 24 '15 10:02 bajtos

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!

trolleycrash avatar Feb 24 '15 19:02 trolleycrash

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

bajtos avatar Feb 25 '15 12:02 bajtos

Thanks, I made some small edits to your addition.

crandmck avatar Feb 25 '15 18:02 crandmck

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- avatar Feb 27 '15 09:02 LetsDoIt-

@LetsDoIt- please post your question to our mailing list, see the Wiki for bug reporting guidelines.

bajtos avatar Feb 27 '15 10:02 bajtos

Sorry for posting it at a wrong place, Done thanks

LetsDoIt- avatar Feb 27 '15 13:02 LetsDoIt-