Expose remote methods to the nested model

96 views
Skip to first unread message

konst...@bodnia.net

unread,
Feb 28, 2018, 5:34:54 AM2/28/18
to LoopbackJS
Hi everyone!

I'm trying to have a remote method described for a specific model exposed as the parent's method nested call (if i'm saying this correctly)

Let's say I have two models:

parent.json:
{ "name": "Parent", "relations": { "model": { "type": "hasMany", "model": "Child" } } }


and child.json

{ "name": "Child", "relations": { "model": { "type": "belongsTo", "model": "Parent", "foreignKey": "parentId", "options": { "nestRemoting": true } } }, "methods": { "prototype.approve": { "accepts": [], "description": "Approves child", "http": [ { "path": "approve", "verb": "put" } ], "returns": { "arg": "data", "type": "Child", "root": true } } } }

That's the setup.

Explorer shows me that I have these this method to as the `/Child/{id}/approve` endpoint.
But parent model doesn't have it `/Parent{id}/Child/{id}/approve`.

What's the best practice to achieve this behaviour?

Thanks everyone!

Nuba Princigalli

unread,
Feb 28, 2018, 2:44:52 PM2/28/18
to loopb...@googlegroups.com
Hi there,


Additionally, you've given the name "model" to the relation going from Parent to Child. Not sure that's what you want, as it'll give you a URL like this: /Parent/{id}/model/{id}/approve which is different from your example.

Hope it helps, good luck!


--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/loopbackjs/c3818f4b-1803-46a4-a1a5-9e293d71caf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

konst...@bodnia.net

unread,
Mar 1, 2018, 2:17:00 PM3/1/18
to LoopbackJS
Okay, I've found the reason why.

You were partly right, it was the naming problem. But it's not the name of the relation that matters (they don't matter in any case).
It's the name of the method.

Instead of "prototype.approve" you had to name it "prototype.__approve__child". Then loopback will regex it and detect as a nested remote method.


Op woensdag 28 februari 2018 20:44:52 UTC+1 schreef Nuba Princigalli:
Hi there,


Additionally, you've given the name "model" to the relation going from Parent to Child. Not sure that's what you want, as it'll give you a URL like this: /Parent/{id}/model/{id}/approve which is different from your example.

Hope it helps, good luck!

On Wed, Feb 28, 2018 at 7:34 AM, <konst...@bodnia.net> wrote:
Hi everyone!

I'm trying to have a remote method described for a specific model exposed as the parent's method nested call (if i'm saying this correctly)

Let's say I have two models:

parent.json:
{ "name": "Parent", "relations": { "model": { "type": "hasMany", "model": "Child" } } }


and child.json

{ "name": "Child", "relations": { "model": { "type": "belongsTo", "model": "Parent", "foreignKey": "parentId", "options": { "nestRemoting": true } } }, "methods": { "prototype.approve": { "accepts": [], "description": "Approves child", "http": [ { "path": "approve", "verb": "put" } ], "returns": { "arg": "data", "type": "Child", "root": true } } } }

That's the setup.

Explorer shows me that I have these this method to as the `/Child/{id}/approve` endpoint.
But parent model doesn't have it `/Parent{id}/Child/{id}/approve`.

What's the best practice to achieve this behaviour?

Thanks everyone!

--
You received this message because you are subscribed to the Google Groups "LoopbackJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to loopbackjs+...@googlegroups.com.

Ganesh B

unread,
Apr 22, 2018, 12:44:42 AM4/22/18
to LoopbackJS
Hi,

A quick question: I have nest APIs for belongsTo as true. How do I reference nested APIs for disabling method or adding ACLs? First level access using prototype.__create__orgGroups for GET /Orgs/{id}/orgGroup works fine. But the Second level nested API access for belongsTo relation using prototype.__create__orgGroups_Orgs or prototype.__create__orgGroups__get__Orgs for GET /Orgs/{id}/orgGroup/Orgs does not work.

Any help with how to access the method name?

Regards,
Ganesh
Reply all
Reply to author
Forward
0 new messages