Rest API equivalent for named scope in model

26 views
Skip to first unread message

Santosh Grampurohit

unread,
Aug 23, 2017, 1:14:00 AM8/23/17
to LoopbackJS

In the documentation for named scope in loopback 3, , the named scope can be defined in boot script as

User.scope('top10Vips', {where: {vip: true}, limit: 10});

Which can be used as
User.top10Vips(function(err, vips) { });


But if I want it to be called by sending the scope name (top10Vips) in the GET query, it does not apply the scope filter.


I tried many variations of this query

http://localhost:8090/api/model/modelname?filter={"order":"timestamp DESC","limit":20,"scope":"top10Vips"}
I get the results without the top10Vips filter applied.


If I add the include filter, I get the error Relation "scope" is not defined for modelname

http://localhost:8090/api/model/Actions?filter={"order":"timestamp DESC","limit":20,"include":{"scope":"top10Vips"}


So what is the rest equivalent of
User.top10Vips(function(err, vips) { });

Andrew Krueger

unread,
Aug 14, 2018, 1:55:36 PM8/14/18
to LoopbackJS
Did you ever figure this out, Santosh? I would like to have this ability as well.

Andrew Krueger

unread,
Aug 14, 2018, 3:31:11 PM8/14/18
to LoopbackJS
Answering this question for other idiots like me:

The scopes defined in your model get added like this automatically:  /ModelName/scopeName
Reply all
Reply to author
Forward
0 new messages