loopback include remote method in query

和自甴很熟 提交于 2019-12-13 01:27:37

问题


I am looking for a way to include the result of a remote method when I make a query.

For example: I am querying Customer models. To include a related model you would use the include filter { filter: { include: ['orders'] } }.

I need to do some processing on some related models before returning results.

What I am looking for is something akin to virtual properties from Mongoose. Is this possible or do I have to create a separate request for each customer after results returned?


回答1:


You can extend the model class and add properties with getter function so that it will get values from other persisted properties.

For example:

module.exports = function(Person) {
  Object.defineProperty(Person.prototype, 
    "fullName", 
    {
      get : function() { return this.firstName + ' ' + this.lastName; }
    });
}

http://docs.strongloop.com/display/LB/Extend+your+API



来源:https://stackoverflow.com/questions/25732251/loopback-include-remote-method-in-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!