javascript - 在环回中包含相关模型的问题

标签 javascript node.js loopbackjs strongloop

我有两个模型Customer和UserProviders

在Customer.json中,具有以下关系

"relations": {
    "userProviders": {
      "type": "hasOne",
      "model": "UserProviders",
      "foreignKey": "userId",
      "options": {
        "disableInclude": true,
        "http": {
          "path": "providers"
        },
        "hidden": [
          "id",
          "providersCount"
        ]
      }
    }
}

UserProviders.json
{
  "name": "UserProviders",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "userId": {
      "type": "objectId",
      "required": true,
      "index": {
        "unique": true
      }
    },
    "providers": {
      "type": [
        "any"
      ],
      "default": []
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

这就是我试图在另一个模型ModelB中查询模型的方式。
let users = ModelB.app.models.Customer;
let UserProvider = ModelB.app.models.UserProviders;

let userData = await users.findOne({
            where: {
            patientId: patientId
          },
            include: {
              relation: 'userProviders',
              scope: {
                fields: ['providers']
              }
            }
    });

对它进行了深入的研究。检查了Joining two models in loopback using include filter结果,但仍无法解决。

为此工作了几天。但是我仍然没有在userData中包含providers字段。任何帮助将非常感激。
我如何包括相关的模型字段?如果我错了,请纠正我。

最佳答案

"options": {
    "disableInclude": true
}

如果使用选项:disableInclude为true,则如果在include语句中使用该关系,则不会获取数据。因此,请尝试将其删除并进行检查。
希望这能解决您的问题。

有关更多信息,请参阅回送文档:https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html

关于javascript - 在环回中包含相关模型的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56408401/

相关文章:

javascript - 如何使用对象初始值设定项来验证表单?

node.js - StrongLoop 的 LoopBack.io : How to turn on HTTP access log?

ios - Cloud Functions 和 DeviceCheck,没有得到 Apple 的回应

javascript - NPM 安装出现 fatal error : reference is not a tree

javascript - "Uncaught ReferenceError: require is not defined"使用 Angular 2/webpack

javascript - NodeJS 请求发布不适用于 HTTPS 网站

node.js - 环回更新嵌入文档

javascript - 如何从数据库获取角色?

javascript - Stripe 无法使用错误 'Uncaught (in promise) Error: We could not retrieve data from the specified Element.'

javascript - 旋转线偏移