环回在查询中包含远程方法 [英] loopback include remote method in query

查看:45
本文介绍了环回在查询中包含远程方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在查询时包含远程方法结果的方法.

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

例如:我正在查询客户模型.要包含相关模型,可以使用包含过滤器{ filter: { include: ['orders'] } }.

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?

推荐答案

您可以扩展模型类并使用getter函数添加属性,以便它将从其他持久属性中获取值.

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

例如:

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

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

这篇关于环回在查询中包含远程方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆