回送3管理嵌入许多基于REST API

时间:2018-11-01 14:14:10

标签: node.js rest loopbackjs

我有一个环回模型pack

{
  "name": "pack",
  "plural": "packs",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string",
      "required": true
    },
    "description1": {
      "type": "string"
    },
    "description2": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {
    "products": {
      "type": "embedsMany",
      "model": "packProduct",
      "property": "products",
      "options": {
        "validate": true,
        "forceId": false
      }
    }
  },
  "acls": [
    {
      "accessType": "*",
      "principalType": "ROLE",
      "principalId": "$unauthenticated",
      "permission": "DENY"
    }
  ],
  "methods": {},
  "strict": true
}

现在使用packProduct模型

{
  "name": "packProduct",
  "plural": "packProducts",
  "base": "Model",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "productId": {
      "type": "string",
      "required": true
    },
    "price": {
      "type": "number",
      "required": true
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {},
  "strict": true
}

当我发送POST请求以仅使用名称创建包时,它可以工作,但是如果我发送

{     名称:“ test”,     产品:[] }

我有The pack instance is not valid. Details: products is not defined in the model (value: undefined).

1 个答案:

答案 0 :(得分:0)

我缺少配置https://loopback.io/doc/en/lb3/Embedded-models-and-relations.html#transient-versus-persistent-for-the-embedded-model的这一部分

需要添加ones= np.ones(3, dtype=bool) #array([True, True, True]) zeros= np.zeros(5-3, dtype=bool) #array([False, False]) arr=np.concatenate((ones,zeros), axis=0, out=None) #arr - array([ True, True, True, False, False]) np.random.shuffle(arr) # now arr - array([False, True, True, True, False])

model-config.json

"packProduct": { "dataSource": "transient", "public": false }

datasources.json