在Loopback中从自定义方法访问其他模型的方法

我正在尝试在Loopback中为基于用户的模型创build自定义方法。

该方法调用login,然后检索用户的angular色,并将其添加到响应中,以便login请求同时保存令牌和angular色信息。

我的问题是,一旦我有令牌信息,我不知道如何调用我创build的angular色&RoleMapping方法…

我如何将这些模型添加到当前范围?

我如何从这个方法访问rootScope?

这是我做到的:

module.exports = function(TiUser) { TiUser.auth = function(credentials, include, fn) { var self = this; self.login(credentials, include, function(err, token) { var role = // Here I would retrieve Role related info authInfo = { token: token, role: role }; fn(err, authInfo); }); }; TiUser.remoteMethod( 'auth', { description: 'Login method with Role data information embedded in return', accepts: [ {arg: 'credentials', type: 'object', required: true, http: {source: 'body'}}, {arg: 'include', type: ['string'], http: {source: 'query' }, description: 'Related objects to include in the response. ' + 'See the description of return value for more details.'} ], returns: { arg: 'accessToken', type: 'object', root: true, description: 'User Model' }, http: {verb: 'post'} } ); }; 

您可以像TiUser.app一样从模型中获取app

所以我称其他模型方法的方式是:

TiUser.app.models.Roles.find