javascript - loopback - append filter before get request -


i using loopback node js app. loopback auto generates crud api. so, trying alter 1 api include table. can adding include filter in query as

/api/expensecategories?filter[include]=vendors

but want /api/expensecategories return table. used beforeremote() method change request before.

my code is:

expensecategories.beforeremote('find', function (ctx, inst, next) {    console.log(ctx.req.url);    ctx.req.url = "/?filter[include]=vendors";    console.log(ctx.req.url);    console.log('get api called');    next(); }); 

this changing request url not changing response, same , table not included. tried changing in req

ctx.req.query = {filter: { include: 'vendors' }};

but no use. idea how can achieve this. both tables relation defined , able desired result making custom api like,

expensecategories.expensecategory = function (cb) {     expensecategories.find({       include: {         relation : 'vendors',       }     }, function(err, data) {     cb(null, data);     });   };    expensecategories.remotemethod (     'expensecategory', {        description: 'get expense types + vendors',        http: {path: '/yes', verb: 'get'},        returns: {arg: 'expensecategory', type: 'string'}     }   ); 

so, table relation , correct. want same result /expensecategories also. help!!!

you can set expensecategory model default scope include vendor adding "scope" section:

"scope": {     "include": "vendor"   } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -