环回关系未填充对象ID的数组 [英] Loopback relations not populating array of Object IDs

查看:44
本文介绍了环回关系未填充对象ID的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我有2种模型:工作流程核心工作流程步骤'

I have 2 models so far: workflow-core,workflow-step'

工作流核心具有一个step属性,该属性的类型为array,包含1个多个步骤.在 workflow-core 上调用get时,响应正文未使用实际的step对象填充step数组.

Workflow core has a steps property that is of type array and contains 1-many steps. When calling get on workflow-core the response body is not populating the steps array with the actual step objects.

workflow-core.json:

{
"name": "workflow-core",
"base": "PersistedModel",
"idInjection": true,
"options": {
  "validateUpsert": true
},
"injectOptionsFromRemoteContext": true,
"properties": {
  "name": {
    "type": "string",
    "required": true,
    "default": "Untitled"
  },
  "user_id": {
    "type": "string",
    "required": false
  },
  "steps": {
    "type": "array",
    "required": false,
    "default": []
  }
},
"validations": [],
"relations": {
  "steps": {
    "model": "workflow-step",
    "type": "embedsMany"
  }
},
"acls": [
  {
    "accessType": "*",
    "principalType": "ROLE",
    "principalId": "$unauthenticated",
    "permission": "DENY"
  }
],
"methods": {}
}

workflow-step.json:

{
"name": "workflow-step",
"base": "PersistedModel",
"idInjection": true,
"options": {
  "validateUpsert": true
},
"properties": {
  "name": {
    "type": "string",
    "required": true,
    "default": "Untitled Step"
  },
  "status": {
    "type": "string",
    "default": "waiting"
  }
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}

Loopback Explorer说我应该得到的(以及我想要的):

What the Loopback Explorer says I should get (and what I want):

{
  "name": "Untitled",
  "user_id": "string",
  "steps": [],
  "id": "string",
  "workflow-steps": [
    {
      "name": "Untitled Step",
      "status": "waiting",
      "id": "string"
    }
  ]
}

我得到的是什么

{
    "name": "Updated with step",
    "user_id": "231569461654",
    "id": "5b75bc769b3143103cb787c2",
    "workflow-steps": [],
    "steps": [
      "5b760fff24ccc23934fef240"
    ]
  }

除了响应正文中没有工作流步骤数组属性之外,hasMany似乎也做同样的事情

hasMany seems to do the same thing except there is no workflow-steps array property in the response body

推荐答案

这最终很容易解决:

  1. 我在workflow-core.json中更改了步骤关系:

  1. I changed the step relation in workflow-core.json:

"relations": {
    "steps": {
       "type": "hasMany",  <-- used hasMany instead of embedsMany
       "model": "WorkflowStep",
       "foreignKey": ""
     }
},

  • 使用api资源管理器窗口时,我需要添加过滤器:{"include":"steps"}

  • When using the api explorer window, I needed to add the filter: {"include": "steps"}

    不确定这是否是其中的一部分,但我按如下方式更改了模型名称:

    Not sure if this was part of it but I changed my model names as follows:

    workflow-core ---> WorkflowCore
    工作流程步骤---> WorkflowStep

    workflow-core ---> WorkflowCore
    workflow-step ---> WorkflowStep

    这篇关于环回关系未填充对象ID的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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