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
Post a Comment