代码之家  ›  专栏  ›  技术社区  ›  Sam Munroe

循环关系不填充对象ID数组

  •  1
  • Sam Munroe  · 技术社区  · 6 年前

    工作流核心 , 工作流步骤 '

    Workflow core有一个数组类型的步骤属性,它包含1个多步骤。打电话时上车 工作流核心 响应体没有用实际的步骤对象填充步骤数组。

    {
    "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": {}
    }
    

    工作流-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": {}
    }
    

    {
      "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似乎做了相同的事情,只是响应体中没有工作流步骤数组属性

    1 回复  |  直到 6 年前
        1
  •  1
  •   Sam Munroe    6 年前

    这最终成为一个简单的解决方案:

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

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

    enter image description here

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


    工作流步骤--->工作流步骤